1. php 实现网络爬虫
pcntl_fork或者swoole_process实现多进程并发。按照每个网页抓取耗时500ms,开200个进程,可以实现每秒400个页面的抓取。
curl实现页面抓取,设置cookie可以实现模拟登录
simple_html_dom 实现页面的解析和DOM处理
如果想要模拟浏览器,可以使用casperJS。用swoole扩展封装一个服务接口给PHP层调用
在这里有一套爬虫系统就是基于上述技术方案实现的,每天会抓取几千万个页面。
2. 求一个PHP写的爬虫,能绕过的。
根据题主的需求,手敲两个小时代码,拿走不谢
from selenium import webdriver
import time
import os
import requests
class Huaban():
def get_picture_url(self, content):
global path
path = "E:\spider\pictures\huaban" + '\\' + content
if not os.path.exists(path):
os.makedirs(path)
url = "http://huaban.com"
driver.maximize_window()
driver.get(url)
time.sleep(8)
try:
driver.find_elements_by_xpath('//input[@name="email"]')[0].send_keys('花瓣账号')
print('user success!')
except:
print('user error!')
time.sleep(3)
try:
driver.find_elements_by_xpath('//input[@name="password"]')[0].send_keys('账号密码')
print('pw success!')
except:
print('pw error!')
time.sleep(3)
3. php有哪些爬虫框架
Beanbun 是用 PHP 编写的多进程网络爬虫框架,具有良好的开放性、高可扩展性。
php爬虫框架phpspider
4. 如何用PHP做网络爬虫
其实用PHP来爬会非常方便,主要是PHP的正则表达式功能在搜集页面连接方面很方便,另外PHP的fopen、file_get_contents以及libcur的函数非常方便的下载网页内容。
5. 你好,我如何用php来实现网络爬虫呢具体一点
以下是访问某音乐网站,并获取其歌曲名等数组的示例,你可以参考:
<?php
header('Content-type:text/html;charset=utf-8');
$doc = file_get_contents('http://www.songtaste.com/music/');
$pa = '{MSL\((.*)\);}';
preg_match_all($pa,$doc,$r);
for($i=0;$i<count($r[1]);$i++)
{
$r1 = explode(', ',$r[1][$i]);
echo '歌曲标题:'. iconv('gb2312','utf-8',$r1[0]) .' 歌曲ID:'.$r1[1].'<br/>';
}
?>
6. PHP爬虫用什么类库
它的元素能够添加到数组中肯定已经存在(定义)了,当时我就想这段代码毫无意义,然后又去查了下手册,才知道isset函数的功能:当变量存在且不为空时才返回true。如果一个变量定义了,但是没有赋值,那么默认为空。上面的代码就是找出数组中第一个不为空的变量。
7. 如何用php 编写网络爬虫
php不太适合用来写网络爬虫,因为几乎没有现成的框架,或者成熟的下载机制,也不太适合做并发处理.
下载页面的话除了一个curl,就是file_get_contents,或者curl_multi来做并发请求.curl可以代理端口,虚假ip,带cookie,带header请求目标页面,下载完成之后解析页面可以用queryList来解析html.写法类似jQuery.
提供给你我之前写的类:curl.php 希望可以帮到你.
QueryList.php和phpQuery.php由于文件太大了,没办法贴上来
<?php
classHttp{
publicfunctioncurlRequest($url,$postData='',$timeOut=10,$httpHeader=array()){
$handle=curl_init();
curl_setopt($handle,CURLOPT_URL,$url);
if($httpHeader){
curl_setopt($handle,CURLOPT_HTTPHEADER,$httpHeader);
}
curl_setopt($handle,CURLOPT_RETURNTRANSFER,true);
curl_setopt($handle,CURLOPT_HEADER,0);curl_setopt($handle,CURLOPT_TIMEOUT,$timeOut);
curl_setopt($handle,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($handle,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($handle,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($handle,CURLOPT_USERAGENT,'Mozilla/5.0(Macintosh;IntelMacOSX10_7_2)AppleWebKit/537.36(KHTML,likeGecko)Chrome/27.0.1453.93Safari/537.36');curl_setopt($handle,CURLOPT_ENCODING,'gzip,deflate,sdch');
if(!empty($postData)){
curl_setopt($handle,CURLOPT_POST,1);
curl_setopt($handle,CURLOPT_POSTFIELDS,$postData);
}
$result['response']=curl_exec($handle);
$result['httpStatus']=curl_getinfo($handle,CURLINFO_HTTP_CODE);
$result['fullInfo']=curl_getinfo($handle);
$result['errorMsg']='';
$result['errorNo']=0;
if(curl_errno($handle)){
$result['errorMsg']=curl_error($handle);
$result['errorNo']=curl_errno($handle);
}
curl_close($handle);
return$result;
}
}
?>
8. php爬虫代码
file_get_contents或者curl,抓取后用正则匹配到数据后入库。
9. 最好语言 php 的基础,学哪门爬虫比较快
那当然是学PHP的爬虫最快咯,PHP的爬虫可以用以下包:
Guzzle: HTTP客户端
DomCrawler: HTML解析
当然,如果你学 python 也应该不是什么难题,不过要先学基础咯,比较麻烦。