Example, PHP gets Sina constellation and horoscope.
function Html2txt ($document) {
- $search = Array (' @ @si ',//Strip out JavaScript
- ' @<[\/\!] *? [^<>]*?> @si ',//Strip out HTML tags
- ' @ ]*?>.*? @siU ',//Strip style tags properly
- ' @ @ ',//Strip multi-line comments including CDATA
- ' @\s+| @'
- );
- $text = Preg_replace ($search, ", $document);
- return $text;
- } bbs.it-home.org
- Function Curl ($url) {
- $ch = Curl_init ();
- curl_setopt ($ch, Curlopt_url, $url);
- curl_setopt ($ch, Curlopt_returntransfer, 1);
- curl_setopt ($ch, Curlopt_referer, ' http://astro.sina.com.cn/fate/astro_aries.html?prourl=0 ');//Forged Source
- curl_setopt ($ch, curlopt_useragent, ' mozilla/'. Mt_rand (2, 9). 0 (Windows NT 6.1; WOW64; RV: '. Mt_rand (10, 30). '. 0) gecko/'. Mt_rand (2000, 2014). ' 0101 firefox/'. Mt_rand (10, 30). 0 ');//Random header
- curl_setopt ($ch, Curlopt_header, 0);
- $data = curl_exec ($ch);
- Curl_close ($ch);
- return $data;
- }
- foreach (Array ($constellation) as $astro) {
- Preg_match ('/(. *?) (.*?) <\/em><\/span>.*? Date of validity: (. *?) Integrated Horoscope (. *?) Love Horoscope (. *?) Work status (. *?) Financial investment (. *?) Health index (. *?) Negotiation index (. *?) Lucky Color (. *?) Lucky number (. *?) Speed dating (. *?) (.*?) <\/div>/isu ', curl (' http://vip.astro.sina.com.cn/astro/view/'. $astro. ' /day/'), $matches);
- File_put_contents ($astro, Json_encode (Array ($matches [1], $matches [2], Html2txt ($matches [3]), Substr_count ($matches [4], ' unset ($matches);
- $array =json_decode (file_get_contents ($astro), true);
- }
- Tomorrow's date
- $mingtian =date (' Ymd ', Strtotime (' +1 Day '));
- foreach (Array ($constellation) as $astro) {
- Preg_match ('/(. *?) (.*?) <\/em><\/span>.*? Date of validity: (. *?) Integrated Horoscope (. *?) Love Horoscope (. *?) Work status (. *?) Financial investment (. *?) Health index (. *?) Negotiation index (. *?) Lucky Color (. *?) Lucky number (. *?) Speed dating (. *?) (.*?) <\/div>/isu ', curl (' http://vip.astro.sina.com.cn/astro/view/'. $astro. ' /day/'. $mingtian. '), $matches);
- Such a regular, can be smaller by the impact of the Sina revision
File_put_contents ($astro, Json_encode (Array ($matches [1], $matches [2], Html2txt ($matches [3]), Substr_count ($matches [4], ' unset ($matches);
- $array 2=json_decode (file_get_contents ($astro), true);
- }
- Today's horoscope
- Print_r ($array)
- Tomorrow's horoscope
- Print_r ($array 2)
- ?>
Copy Code |