Skip to content

Instantly share code, notes, and snippets.

@underdown
Last active September 14, 2017 18:02
Show Gist options
  • Select an option

  • Save underdown/cad9913679ca22541db4134772a076bd to your computer and use it in GitHub Desktop.

Select an option

Save underdown/cad9913679ca22541db4134772a076bd to your computer and use it in GitHub Desktop.
Drudge Report Mobile Friendly php Scraper/Script
/* This is a script i use to make drudge report mobile friendly. view @ ryanunderdown.com/drudge
Please excuse the ugly procedural php
*/
<?php
function getPage($url, $referer, $agent, $header, $timeout) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_PROXY, $proxy);
// curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$result['EXE'] = curl_exec($ch);
$result['INF'] = curl_getinfo($ch);
$result['ERR'] = curl_error($ch);
curl_close($ch);
return $result;
}
$result = getPage(
'http://www.drudgereport.com/',
'http://www.drudgereport.com/',
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.8.8',
1,
5);
if (empty($result['ERR'])) {
preg_match_all("(<a href=\"(.*)\".*>(.*)</a>)siU",
$result['EXE'], $matches);
$removematch = array("http://news.myway.com/index/id/national%7Cap.html","http://news.myway.com/index/id/business%7Cap.html","http://www.syracuse.com/newsflash/index.ssf/entertainment","http://hosted.ap.org/dynamic/fronts/HOME\?SITE=AP\&amp\;SECTION=HOME","http://www.bloomberg.com/","http://www.dpa-international.com/news/international/","http://www.itar-tass.com/en/","https://uk.news.yahoo.com/uk/","http://www.prnewswire.com/news-releases/news-releases-list/","http://www.wenn.com/all-news/","http://www.xinhuanet.com/english/","http://www.thepaperboy.com/uk/front-pages.cfm","http://boxofficemojo.com/daily/chart/","http://www.antiwar.com/","http://www.theatlantic.com/","http://www.theatlanticwire.com/","http://bostonherald.com/news","http://www.businessinsider.com/","http://www.buzzfeed.com/","http://cbslocal.com/2015/08/31/daily-news-tips-from-cbs-local-sites/","http://www.ew.com/ew/","http://www.esquire.com/","http://freebeacon.com/","http://www.freerepublic.com/home.htm","http://thehill.com","https://firstlook.org/theintercept/","http://www.jpost.com","http://www.mediaite.com/","http://www.motherjones.com/","http://www.nbcnews.com/","http://www.nydailynews.com/","http://www.nytimes.com/timeswire/","http://pjmedia.com/","http://news.sky.com/","http://www.splashnewsonline.com/","http://www.dailymail.co.uk/news/headlines/index.html","http://www.guardian.co.uk/world","http://www.theverge.com/","http://www.vox.com/","http://online.wsj.com/public/page/news-viewer.html","http://wabcradio.com/","http://www.iheart.com/live/5874/\?autoplay\=true","http://www.kfiam640.com/main.html","http://www.wtop.com/","http://www.foxnews.com/category/fox-news-first","http://WSJ.com/10point","http://www.nytimes.com/politics/first-draft/","http://time.com/newsletter/politics/","http://www.washingtonpost.com/news/powerpost/wp/category/the-daily-202/","http://www.realclearpolitics.com/epolls/latest_polls/","http://pagesix.com/author/cindy-adams\/","http://www.dailymail.co.uk/tvshowbiz/columnist-1000601/Baz-Bamigboye.html","http://blogs.herald.com/dave_barrys_blog\/","http://www.weeklystandard.com/author/fred-barnes","http://washingtonexaminer.com/author/michael-barone","http://washingtonexaminer.com/politics/washington-secrets","http://www.thesun.co.uk/sol/homepage/showbiz/bizarre/","http://www.cnn.com/POLITICS/borger.commentary/archive","http://newsbusters.org/author/brent-bozell","http://www.france24.com/en/","http://www.broadcastingcable.com/","http://www.Adweek.com","http://english.kyodonews.jp/","http://hosted.ap.org/dynamic/fronts/RAW?SITE=AP\&SECTION\=HOME","http://www.emirates247.com","http://www.washingtontimes.com","http://www.ananova.com/news/index.html\?nav_src=news\&menu=news.latestheadlines","http://www.bloomberg.com/news/worldwide/","http://home.businesswire.com/portal/site/home/index.jsp?front_door=true\&headlineSearchConfigBO\=v2\*G0","http://www.earthtimes.org/articles/cat/World.html","http://news.nasdaq.com/aspxcontent/newsheadlines.aspx\?\&SourceCode=","http://www.efe.com/principal.asp?opcion=0&idioma\=INGLES","http://www.ians.in","http://www.interfax.com","http://www2.irna.ir/en/","http://www.itar-tass.com/eng/level2.html\?GroupID\=146","http://home.kyodo.co.jp/","http://www.mcclatchydc.com","http://english.pravda.ru/allnews_en.html","http://uk.news.yahoo.com/75/","http://online.wsj.com/home-page","http://www.usatoday.com/","http://nationaljournal.com/","http://www.ptinews.com/","http://www.prnewswire.com/","http://biz.yahoo.com/n/y/y0010.html","http://public.shns.com","http://usinfo.state.gov/usinfo/products/washfile.html","http://uk.news.yahoo.com/588/","http://www.xinhuanet.com/english/index.htm","http://english.yonhapnews.co.kr/","http://www.newseum.org/todaysfrontpages/","http://www.topix.net","http://www.cnn.com","http://tvbythenumbers.com/","http://boxofficemojo.com/daily/","http://www.abcnews.com/","http://www.accesshollywood.com/","http://adage.com/news_and_features/deadline/index.html","http://news.bbc.co.uk/default.stm","http://www.bbc.co.uk/worldservice/news/summary.ram","http://www.bild.com","http://www.billboard.com","http://www.boston.com/globe/","http://news.bostonherald.com/","http://www.breitbart.com/","http://www.tvinsite.com/broadcastingcable/index.asp?layout=webzine","http://www.cbsnews.com","http://www.c-span.org","http://www.suntimes.com/","http://www.chicagotribune.com","http://www.csmonitor.com/","http://www.cnbc.com/","http://www.cnn.com","http://www.cnn.com/POLITICS/blogs/politicalticker","http://thedailybeast.com","http://dailykos.com/","http://www.thedailyswarm.com","http://www.variety.com/","http://www.spiegel.de/international","http://www.eonline.com/index.jsp","http://www.economist.com","http://www.editorandpublisher.com/eandp/index.jsp","http://www.emiratestodayonline.com/","http://www.pathfinder.com/ew/","http://www.ft.com","http://www.forbes.com/","http://www.foxnews.com","http://www.thefoxnation.com/","http://www.freerepublic.com/tag/news-forum/?ao=1","http://www.gawker.com","http://www.hotair.com","http://www.hellomagazine.com/","http://www.hillnews.com","http://www.hollywoodreporter.com","http://www.huffingtonpost.com","http://www.humanevents.com","http://www.iafrica.com","http://www.iht.com","http://www.infowars.com/","http://www.investors.com","http://www.jpost.com/","http://www.dailynewslosangeles.com/","http://www.latimes.com","http://www.lucianne.com","http://www.mediaweek.com","http://www.msnbc.msn.com","http://www.TheNation.com","http://www.nationalenquirer.com/","http://www.nationalreview.com","http://www.thenewrepublic.com/","http://nymag.com","http://www.nydailynews.com/news/headlines/index.html","http://www.observer.com/","http://www.nypost.com/","http://www.nytimes.com","http://www.newyorker.com","http://newsbusters.org/","http://www.newsbytes.com","http://www.newsmax.com","http://www.newsweek.com/","http://www.kcna.co.jp/index-e.htm","http://www.people.com","http://www.philly.com/mld/inquirer","http://www.philly.com/mld/dailynews","http://www.politico.com/","http://radaronline.com/","http://realclearpolitics.com","http://www.reasonmag.com/","http://www.redstate.com/","http://www.rollcall.com/","http://www.rollingstone.com","http://www.salon.com/","http://www.sfgate.com/chronicle/","http://www.seattletimes.com","http://www.sky.com/skynews/home","http://www.slate.com","http://thesmokinggun.com/","http://splash.mainstreamdata.com/splashrss","http://www.starmagazine.com","http://www.smh.com.au/text/index.html","http://talkingpointsmemo.com","http://time.com","http://www.TMZ.com","http://www.dailymail.co.uk/home/index.html","http://www.mirror.co.uk","http://www.dailyrecord.co.uk/news/","http://www.thisislondon.co.uk/news","http://www.express.co.uk","http://www.guardian.co.uk/","http://www.independent.co.uk/","http://www.newsoftheworld.co.uk/","http://www.thesun.co.uk","http://www.telegraph.co.uk/","http://www.usnews.com/usnews/home.htm","http://www.usatoday.com/printedition/news/index.htm","http://www.vanityfair.com","http://www.villagevoice.com/","http://www.washingtonexaminer.com/","http://www.washingtonpost.com/","http://www.washingtontimes.com/","http://www.weeklystandard.com","http://www.wnd.com/","http://www.wowowow.com/","http://www.x17online.com","http://www.lasvegassun.com/news/world/","http://ap.tbo.com/breaking/national/","http://www.lasvegassun.com/news/beltway/","http://news.yahoo.com/business","http://www.breitbart.com/detail.php\?ch\=BNAPENTER\&catnum\=6","http://news.myway.com/index/id/top|ap.html","http://www.newsday.com/news/nationworld/wire/","http://ap.tbo.com/breaking/national/","http://search.news.yahoo.com/search/news?p=a&c=news_photos","http://hosted.ap.org/dynamic/files/specials/videolineups/audio.html?SITE=MNROC&SECTION=HOME","http://english.yonhapnews.co.kr/","http://www.newseum.org/todaysfrontpages/","http://www.topix.net","http://boxofficemojo.com/daily/","http://www.theblaze.com/","http://dailycaller.com/","http://blogs.abcnews.com/thenote/","http://www.politico.com/playbook/","http://firstread.msnbc.msn.com/","http://voices.washingtonpost.com/44/the-rundown/","http://www.drudgereport.com/","http://www.mirror.co.uk/3am/","https://www.axios.com/","http://www.nypost.com/gossip/cindy/cindy.htm","http://marcambinder.theatlantic.com/","http://thehill.com/news","http://www.deadline.com/hollywood/","http://www.showbuzzdaily.com/","http://www.editorandpublisher.com/home.aspx","https://www.axios.com/axios-am/","http://www.celebrityservice.com/","http://www.zerohedge.com/","http://pagesix.com/author/cindy-adams/","http://www.lifezette.com/","http://alter.newsweek.msnbc.com", "http://www.c-span.org","http://www.efe.com/principal.asp?opcion=0&idioma=INGLES");
?>
<!doctype="html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>mindrudge</title>
<link href="typebase.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/jquery-1.3.2.min.js"></script>
<meta name="viewport" content="width=device-width; initial-scale=1.0;">
<script type="text/javascript">
window.addEventListener("load", function() { setTimeout(loaded, 100) }, false);
function loaded() {
window.scrollTo(0, 1); // pan to the bottom, hides the location bar
}
</script>
<script type="text/javascript">var _gaq=_gaq||[];_gaq.push(['_setAccount','UA-15543101-2']);_gaq.push(['_trackPageview']);(function(){var ga=document.createElement('script');ga.type='text/javascript';ga.async=true;ga.src=('https:'==document.location.protocol?'https://ssl':'http://www')+'.google-analytics.com/ga.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(ga,s);})();</script>
</head>
<body onorientationchange="updateOrientation();">
<div id="page_wrapper">
<div id="header">
<h1 class="strong"><a href="/drudge/">drudge</a> </h1>
</div>
<div class="post_cont">
<?php
function parse_url_domain ($url) {
$parsed = parse_url($url);
$hostname = $parsed['host'];
return $hostname;
}
for ($i = 0; $i < count($matches[1]); $i++) {
$matches[1][$i] = strip_tags($matches[1][$i]);
}
$unique = array(array_diff($matches[1],$removematch));
for ($i = 0; $i < count($unique[0]); $i++) {
if (!is_null($unique[0][$i])) {
if (!is_null($matches[2][$i])) {
$trimurl = parse_url_domain($unique[0][$i]);
if ($trimurl != "adserver.adtechus.com"){ //i forget why i added this
echo "<div class=\"content\"><h3><a href=\"";
echo $unique[0][$i];
echo "\">";
echo $matches[2][$i];
echo "</a></h3><div class=\"sp\">".$trimurl."</div></div>\n";
} else {$i++;}
}
}
}
echo "</div>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment