<?php
// Scraping number of results for Ask.Com
$reg = '#<span id=\'indexLast\' class=\'b\'>[:alnum:]</span> of (.*) for#Usi';
$keyword = 'SEO';
$cookie = '';
// Get a cookie
$ch = curl_init('http://www.ask.com/');
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $true);
$response = curl_exec($ch);
// Get the results
$ch = curl_init('http://www.ask.com/web?qsrc=2417&o=312&l=dir&q='.urlencode($keyword));
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $true);
$result = curl_exec($ch);
curl_close($ch);
// Search for result
if(preg_match($regex, $result, $match)){
$number = str_replace(',', '', $match[0]);
$number = number_format($number, 0, '.', ' ';
echo $number . ' results for keyword <strong>'.$keyword.'</strong>';
}
else{
echo 'Sorry, could not retrieve results for <strong>'.$keyword.'</strong>';
}
?>
<?php
// Scraping number of results for Ask.Com
$reg = '#<span id=\'indexLast\' class=\'b\'>[:alnum:]</span> of (.*) for#Usi';
$scrape = $_POST["askkeyword"];
$keyword = "$scrape";
$cookie = '';
</form></center>
<center>Link Scraper by 00CivicEX</center>
<center><form method="post" action="askresult.php">
[URL="http://www.blackhatworld.com/blackhat-seo/<input"]URL:<input[/URL] type="text" size="12" maxlength="40" name="askkeyword"><br />
<input type="submit" value="Scrape Links" name="submit">
</form></center>
storeLink($number,$keyword);
echo "<br />Keyword Number Stored: $number,$keyword";
function storeLink($number,$keyword) {
$query = "INSERT INTO links (number, keyword) VALUES ('$number', '$keyword')";
mysql_query($query) or die('Error, insert query failed');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Scraper
</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
$username="xxxxxxxxx";
$password="xxxxxxxxx";
$database="xxxxxxxxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
function storeLink($url,$gathered_from) {
$query = "INSERT INTO links (url, gathered_from) VALUES ('$url', '$gathered_from')";
mysql_query($query) or die('Error, insert query failed');
}
$scrapekey = $_POST["keyword"];
$target_url = "[URL]http://www.ask.com/web?qsrc=2417&o=312&l=dir&q=$scrapekey[/URL]";
$userAgent = 'Googlebot/2.1 ([URL]http://www.googlebot.com/bot.html)'[/URL];
// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
storeLink($url,$target_url);
echo "<br />Link stored: $url";
}
mysql_close();
?>
<center><FORM ACTION="home.html">
<INPUT TYPE=SUBMIT VALUE="Results">
</FORM></center>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/URL]">
<html xmlns="[URL]http://www.w3.org/1999/xhtml[/URL]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Scraper
</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
$username="xxxxxx";
$password="xxxxxx";
$database="xxxxxx";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
function storeLink($url,$gathered_from) {
$query = "INSERT INTO links (url, gathered_from) VALUES ('$url', '$gathered_from')";
mysql_query($query) or die('Error, insert query failed');
}
$scrapekey = $_POST["keyword"];
$target_url = "[URL]http://www.ask.com/web?qsrc=2417&o=312&l=dir&q=$scrapekey[/URL]";
$userAgent = 'Googlebot/2.1 ([URL]http://www.googlebot.com/bot.html)'[/URL];
// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
echo "<br />cURL error number:" .curl_errno($ch);
echo "<br />cURL error:" . curl_error($ch);
exit;
}
// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xp = new domxpath($dom);
//searches the ask.com for <span> tags and narrows it down to the spans class
$titles = $xp->query("/html/body//span[@class = 'b']");
foreach ($titles as $node) {
//sifts through what it finds and only shows the text content
print $node->textContent . " ";
}
mysql_close();
?>
<center><FORM ACTION="home.html">
<INPUT TYPE=SUBMIT VALUE="Results">
</FORM></center>
</body>
</html>
<?php
// this is the string its suppose to match
$regex = "#<span id=\'indexLast\' class=\'b\'>[[:alnum:]]</span> of (.*) for#Usi";
$keyword = 'nintendo';
$cookie = '';
$target_url = "[URL]http://www.ask.com/web?qsrc=2417&o=312&l=dir&q='[/URL], urlencode($keyword)'";
$userAgent = 'Googlebot/2.1 ([URL]http://www.googlebot.com/bot.html)'[/URL];
// Get a cookie
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$target_url);
curl_setopt($ch,CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch,CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, $true);
$response = curl_exec($ch);
// Get the results
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch,CURLOPT_URL,$target_url);
curl_setopt($ch,CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, $true);
$result = curl_exec($ch);
curl_close($ch);
// Search for result
if (preg_match($regex,$result,$match)){
$number = str_replace(',', '', $match[0]);
$number = number_format($number, 0, '.', ' ');
echo $number . ' results for keyword <strong>'.$keyword.'</strong>';
}else{
echo 'Sorry, could not retrieve results for <strong>'.$keyword.'</strong>';
}
?>
<span id='indexLast' class='b'>10</span> of 25,100,000 for
any ideas what it is? is it an encoding/character set issue??
jay
<?php
$data = file_get_contents('http://www.ask.com/web?q=paper&search=search&qsrc=0&o=0&l=dir');
$regex = '/<\/span> of (.+?) for/';
preg_match($regex,$data,$match);
echo $match[1];
?>
<?php
$search_for = urlencode("search for some shizzzzzzzz");
$data = file_get_contents('http://www.ask.com/web?qsrc=2417&o=0&l=dir&q=' . $search_for);
$regex = '/<\/span> of (.+?) for/';
preg_match($regex,$data,$match);
echo $match[1];
?>