Last active
August 29, 2015 13:59
-
-
Save hugowan/10581957 to your computer and use it in GitHub Desktop.
lego
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$lego = new lego(); | |
$lego->init(); | |
class lego { | |
private $yql = 'https://query.yahooapis.com/v1/public/yql?q='; | |
public function init() | |
{ | |
$query = urlencode('select * from html where url = "http://www.brickpicker.com/bpms/set.cfm?set=6866-1"'); | |
$url = $this->yql . $query; | |
$data = $this->_curl($url); | |
if ( ! empty($data)) | |
{ | |
$xml = simplexml_load_string($data); | |
echo '<pre>'; | |
print_r($xml); | |
echo '</pre>'; | |
// $results = $xml->results(); | |
} | |
// var_dump($data); | |
} | |
private function _curl($url) | |
{ | |
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; | |
$header[0].= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; | |
$referers = array("google.com", "yahoo.com", "msn.com", "ask.com", "live.com"); | |
$choice = array_rand($referers); | |
$referer = "http://" . $referers[$choice] . ""; | |
$browsers[0] = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3"; | |
$browsers[1] = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20060918 Firefox/2.0"; | |
$browsers[2] = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3"; | |
$browsers[3] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)"; | |
$browser = $browsers[array_rand($browsers)]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_USERAGENT, $browser); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($ch, CURLOPT_REFERER, $referer); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
// curl_setopt($ch, CURLOPT_MAXREDIRS, 7); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt'); // use | |
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); // download | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
return $data; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$str = '%22%3Ccategories%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Mar%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Apr%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27May%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Jun%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Jul%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Aug%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Sep%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Oct%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Nov%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Dec%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Jan%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3Ccategory%20name%3D%27Feb%27%20%2F%3E%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%3C%2Fcategories%3E%22%20%2B'; | |
$str = urldecode($str); | |
preg_match_all('/category.*=[\']([^\']+)[\']/i', $str, $matches); | |
echo '<pre>'; | |
print_r($matches); | |
echo '</pre>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment