What is a simple php crawler case?

Source: Internet
Author: User
I am a novice php, especially the use of PHP very poor.
Is there a simple example of a PHP crawler that inspires the Novice's desire to love PHP.
Like crawling a Web site's database with PHP?
How to use PHP different methods and not the same function or use regular ratio. With file or something?

Reply content:

I am a novice php, especially the use of PHP very poor.
Is there a simple example of a PHP crawler that inspires the Novice's desire to love PHP.
Like crawling a Web site's database with PHP?
How to use PHP different methods and not the same function or use regular ratio. With file or something?

Https://github.com/search?utf8=%E2%9C%93&q=php+crawler

Can you give me a good question?
Who tells you that you can crawl someone else's Web site database? data! = database.
Methods of obtaining HTML content can be used,,, file_get_contents() curl fopen fsockopen , etc

The simplest: Get Segmentfault home content:

echo file_get_contents('https://segmentfault.com/');

HTML Content Extraction

You may need to extract the content of the page, you can use regular expressions, but not recommended, once the site revision is difficult to maintain, or HTML content is irregular,

It is recommended phpquery to use such DOM parsing, which is developed by people based on Phpqueryquerylist


  
   find('article.newsentry') as $article) {    $item['time']    = trim($article->find('time',            0)->plaintext);    $item['title']   = trim($article->find('h2.newstitle',    0)->plaintext);    //$item['content'] = trim($article->find('div.newscontent', 0)->plaintext);    $news[] = $item;}print_r($news);

For example, the above is the simple HTML DOM this PHP DOM analysis library to collect php.net home news, it is convenient to do the DOM like jquery, to get the data needed in the HTML.
Http://simplehtmldom.sourceforge.net/manual.htm

  • Related Article

    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.