morze
Постоялец
- Регистрация
- 9 Окт 2006
- Сообщения
- 74
- Реакции
- 51
- Автор темы
- #1
Код:
<?
//
function getadwords ( $keyword, &$err = 1 )
{
global $proxy;
$ch = curl_init();
// curl_setopt($ch, CURLOPT_URL,'https://adwords.google.com/select/VariationsTool?adgroupid=0&campaignid=0&keywords=' . urlencode ($keyword) . '&adgroupIntegrated=false&skipLogin=true¤cyCode=USD&maxCpcOverride=&targetLanguages=en&targetCountries=*&synonyms=true&nocache=1146820018203');
curl_setopt($ch, CURLOPT_URL,'https://adwords.google.com/select/VariationsTool?adgroupid=0&campaignid=0&keywords=' . urlencode ($keyword) . '&adgroupIntegrated=false&skipLogin=true¤cyCode=USD&maxCpcOverride=&targetLanguages=es&targetCountries=*&synonyms=true&nocache=1146820018203');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, './cc-adwords.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cc-adwords.txt');
curl_setopt($ch, CURLOPT_REFERER, "http://adwords.google.com");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$randproxy = rand (0, count ($proxy) - 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy [$randproxy]);
$html = curl_exec ($ch);
$succeeded = curl_errno($ch) == 0 ? true : false;
$err = curl_errno($ch).':'.curl_error($ch);
if(!$succeeded)
{
print '- [' . $keyword . '] (' . $err . ")\n";
unset ($proxy [$randproxy]);
$err = 1;
} else
{
print '+ [' . $keyword . ']' . "\n";
$err = 0;
}
preg_match_all ('/criteria\.push\(new kpCriterion\(\'([\w\s]+)\', /is', $html, $match_all);
return ($match_all [1]);
curl_close ( $ch );
}
$proxy = array ();
$fi = fopen ('tut-url-otkuda-brat-proxy', 'r');
if (! $fi)
{
print '- cannot open proxy ' . "\n";
die;
}
while (!feof ($fi))
{
$proxy [] = trim (fgets ($fi, 4096));
}
fclose ($fi);
$proxy = array_slice ($proxy, 0, 100);
print '* proxy: ' . count ($proxy) . ' - ' . $proxy [0] . "\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://adwords.google.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, './cc-adwords.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cc-adwords.txt');
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$html = curl_exec ($ch);
$succeeded = curl_errno ($ch) == 0 ? true : false;
$err = curl_errno ($ch) . ':' . curl_error ($ch);
if(!$succeeded)
{
print $err;
}
curl_close ($ch);
$keywords = array ();
$skeywords = array ('telefono', 'negocio');
$err = 0;
foreach ($skeywords as $skeyword)
{
$bkeywords = getadwords ( $skeyword, $err );
$i = 0;
while ($err == 1 && $i < 4)
{
$bkeywords = getadwords ( $skeyword, $err );
$i ++ ;
}
foreach ($bkeywords as $keyword)
{
$keywords [$keyword] = $keyword;
$akeywords = getadwords ( $keyword );
foreach ($akeywords as $keyword)
{
$keywords [$keyword] = $keyword;
}
print '* ' . $i . '=' . count ($keywords) . "\n";
}
}
$fo = fopen ('./adwords-es.txt', 'a+');
foreach ($keywords as $keyword)
{
fputs ($fo, $keyword . "\n");
}
fclose ($fo);
print '+ ' . count ($keywords) . "\n";
?>