rendered paste body<?php
//ezinearticles.com scraping script
//scrapes ezine articles and puts the content in .txt files named by page title
//if you dont like my sloppy code, write your own crap
//written by dissipate , last revised 15 may 2007
for( $i = 0; $i < 1; $i++ ) {
sleep( rand( 2,7 ) );
$x = $i * 100;
$keyword = "site:ezinearticles.com inurl:id acne";
$file =
file_get_contents("http://www.google.com/search?safe=off&q=".urlencode($keyword)."&start='.$x.'&num=100&sa=N'");
if( $file ) {
preg_match_all( '/<h2 class=r><a href="(.+?)" class=l/is', $file, $output, PREG_SET_ORDER );
if( count( $output ) > 0 ) {
foreach( $output as $item ) {
if( $item[1] ) { $urls[] = $item[1]; }
echo "Now Scraping : " . $item[1] . "\n";
scrapeit($item[1]);
//echo "$item[1]<br>";
}
}
}
}
function scrapeit($url)
{
$ch = curl_init();
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$scrape = curl_exec ($ch);
$scrape = str_replace(chr(10), '', str_replace(chr(13), '', stripslashes($scrape)));
curl_close ($ch);
preg_match("%<!-- google_ad_section_start -->(.*)<!-- google_ad_section_end -->%", $scrape, $article, PREG_OFFSET_CAPTURE);
preg_match("%<title>(.*)</title>%",$scrape, $title, PREG_OFFSET_CAPTURE);
$article[0][0] = preg_replace('%<table(.*)</table>%', "", $article[0][0]);
$newarticle = remove_html($article[0][0]);
$newtitle = remove_html($title[0][0]) . '.txt';
$newtitle = str_replace(chr(32), '-', str_replace(chr(63), '',$newtitle));
//echo "title is : " . $newtitle . "\n";
$fp = fopen($newtitle, "w+");
fwrite($fp, $newarticle);
}
function remove_html($html)
{
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out html tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$html = preg_replace ($search, $replace, $html);
return $html;
}
?>