在php中抓取数据时,使用用户ip发送请求


Send request with user ip when scraping data in php

我遇到了一个问题,我有一个url有地理位置限制,只能从欧洲或美国查看。我的位置是亚洲。我想从url中提取所有href。

然而,我正在使用curl,但问题是它发送服务器ip地址,我希望使用用户ip地址发出请求,以便跟踪用户访问过的链接。如果你能指导我如何在不使用curl的情况下使用用户ip地址发送请求,我将不胜感激。

以下是源代码。我正在访问的网址是:

http&colon//partnerads.ysm.yahoo.com/ypa/?ct=2&c=000000809&u=http%3A%2F%2Trouve.autocut.fr%2F_test.php%3Fq%3Tarif%2520skoda%2520superior%2520combi&r=&w=1&tv=&tt=&lo=&ty=&ts=1458721731523&ao=&h=1&CoNo=3292b85181511c0a&dT=1&er=0&si=p-自动结果_FRA_SERP_2%3A600x796

<?php
include_once 'simple_html_dom.php';
$html = file_get_html('iframe.html');
// find iframe from within html doc
foreach($html->find('iframe') as $iframe)
{
  $src = $iframe->getAttribute('src');     // src extracted 
  $ch = curl_init();  // Initialise a cURL handle
  // Set any other cURL options that are required
  curl_setopt($ch, CURLOPT_HEADER, TRUE);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
  curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36');
  curl_setopt($ch, CURLOPT_URL,$src);
  $results = curl_exec($ch);  // Execute a cURL request
  //echo curl_error($ch);
  curl_close($ch);    // Closing the curl
  $bool = TRUE; $match = array(); $int = 0;
  while(preg_match('/<a[^>]+href=([''"])(.+?)'1[^>]*>/i', $results, $matches))
  {
    if($bool)
    {
      // print captured group that's actually the url your searching for
      echo $matches[2].'<br>'.'<br>'.'<br>'.'<br>';
      $bool = false;
    }
  }
}

您可以使用代理。

$ip = '100.100.100.100:234' //example $ip
curl_setopt($ch, CURLOPT_PROXY,$ip);

无卷曲:

$aContext = array(
    'http' => array(
        'proxy' => 'tcp://'.$ip,
        'request_fulluri' => true,
    ),
);
$cxContext = stream_context_create($aContext);
$sFile = file_get_contents("http://www.google.com", False, $cxContext);

如果你在寻找代理,有一些地址很容易刮到:

'http://proxylist.hidemyass.com/',
'http://ipaddress.com/proxy-list/',
'http://nntime.com/proxy-ip-'.$i.'.htm',
'http://www.proxylisty.com/ip-proxylist-'.$i

超过2000 ips