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