可否帮忙写一个单页页的PHP采集程序,并附下实例
可否帮忙写一个单页页的PHP采集程序,并附上实例
比方说,我要采集这个页面:http://news.163.com/12/0613/20/83TJ7PA700014JB6.html
要求:
采集标题
采集正文
谢谢!
------解决方案--------------------
首先去http://simplehtmldom.sourceforge.net/index.htm(点击Download latest version form Sourceforge.)下载一个simple_html_dom.php,傻瓜式的正则,另官网上有详细教程,很容易看懂。
<br /> header("Content-type: text/html; charset=gb2312");<br /> require dirname(__FILE__) . '/simple_html_dom.php';<br /> $ch = curl_init();<br /> curl_setopt($ch, CURLOPT_URL, 'http://news.163.com/12/0613/20/83TJ7PA700014JB6.html');<br /> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br /> 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');<br /> $htmls = curl_exec($ch);<br /> curl_close($ch);<br /> $html = str_get_html($htmls);<br /> foreach($html->find('#h1title') as $title){ <br /> echo strip_tags($title).'<br />';//标题<br /> }<br /> foreach($html->find('#endText') as $content){ <br /> echo strip_tags($content);//正文<br /> }
注:curl模拟Mozilla浏览器抓取,比file_get_contents()解析速度更快。strip_tags() 用以去除那个邪恶的iframe广告,反正你需要的是“采集标题”和“采集正文”冗余的html标签对你无用。
------解决方案--------------------
本文为大家介绍有关如何运用PHP获取QQ邮箱好友的方法。PHP有一个扩展是curl扩展,该扩展一般用于采集数据。但是也可以实现模拟登陆,通过模拟登陆来登陆QQ邮箱,再利用curl的采集来获取邮箱的好友列表。以上是实现原理,理解袁莉以后我们来看实现过程。具体的PHP获取QQ邮箱好友的代码如下:
1. 2.class QQHttp {
3. var $cookie = '';
4. function __cunstrut() {
5. }
6. function makeForm() {
7. $form = array(
8. 'url' => "http://mail.qq.com/cgi-bin/loginpage",
9. );
10. $data = $this->curlFunc($form);
11. preg_match('/name="ts"svalue="(d+)"/',$data['html'], $tspre);
12. $ts = $tspre[1];
13. preg_match('/action="http://(md+).mail.qq.com/',$data['html'], $server);
14. $server_no = $server[1];
15. /* login.html 载入 */
16. $html = file_get_contents(dirname(__FILE__).'/login.htm');
17. $html = str_replace('{_ts_}',$ts, $html);
18. $html = str_replace('{_server_no_}',$server_no, $html);
19. return $html;
20. }
21. function curlFunc($array)
22. {
23. $ch = curl_init();
24. curl_setopt($ch, CURLOPT_URL, $array['url']);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
