我正在尝试使用代码中提供的 dork 从 Google 抓取 URL。
现在我正在使用 cURL,但它说“curl_init() 在未定义的函数中”
到目前为止,我得到了:
//This is the Pattern for URL finding
$pattern = "~^(http|ftp)(s)?\:\/\/((([a-z0-9]{1,25})(\.)?){2,7})($|/.*$)~i";
//Enter your dork here.
$dork = "inurl: login.php";
//Set the Useragent
$ua = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311";
//Initialize cURL
$ch = curl_init();
$url = "http://www.google.com/search?q=".$dork;
$timeout = 10;
curl_setopt($ch,CURL_OPT, $url);
curl_setopt($ch,CURLOPT_USERAGENT,$ua);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$exec = curl_exec($ch);
$contents = curl_getinfo($ch);
//curl_close($ch);
//Set empty url array
$urls = array();
//Find urls on page you just grabbed ^
preg_match_all($pattern, $contents, $matches);
//Assign the urls to the empty array urls
foreach ($matches[0] as $match)
{
$urls[] = "{$match}";
}
//Remove any duplicates in url array
$vurls = array_unique($urls);
//take out spaces
$urlStr = implode("", $urls);
//count number of unique urls
$count = count($vurls);
//Writing to text file
$fh = fopen('wp.txt', 'w');
fwrite($fh, $urlStr);
fclose($fh);
//Echoing # of urls found.
echo "Done. Found {$count} sites.\n";
我不知道出了什么问题,我也试图让它刮掉多个页面。但想知道我应该如何解决这个问题。
如果有人能指出我正确的方向,那将非常有帮助,我不需要用勺子喂食。