Can you help write a single-page PHP collection program and attach an instance? how can this problem be solved?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.