Can you write a single-page PHP collection program and attach an instance? for example, I want to collect this page: news.163.com1206132083TJ7PA700014JB6.html. requirement: collect the title collection body. thank you! ------ Solution ------------------ first go to simplehtmldom. sourceforge. netinde to help write a single-page PHP collection program, and attach an instance
For example, I want to collect this page: http://news.163.com/12/0613/20/83TJ7PA700014JB6.html
Requirements:
Collection title
Collect Body
Thank you!
------ Solution --------------------
First go to the http://simplehtmldom.sourceforge.net/index.htm (click Download latest version form Sourceforge.) Download a simple_html_dom.php, silly regular expression, the other official website has a detailed tutorial, it is easy to understand.
PHP code
Header ("Content-type: text/html; charset = gb2312"); require dirname (_ FILE __). '/simple_html_dom.php'; $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, 'http: // scheme); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ($ ch, CURLOPT_USERAGENT, 'mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv: 1.9.1.2) Gecko/20090729 Firefox/3.5.2 gtb5 '); $ htmls = curl_exec ($ ch); curl_close ($ ch); $ html = str_get_html ($ htmls); foreach ($ html-> find ('# h1title ') as $ title) {echo strip_tags ($ title ).'
'; // Title} foreach ($ html-> find (' # endtext') as $ content) {echo strip_tags ($ content); // Body}
------ Solution --------------------
PHP:
------ Solution --------------------
You can capture the page. The title is between the title tags and the body. you can use regular expressions to remove unnecessary content.