PHP头条
热点:

php使用Snoopy.class.php做httpgetpost请求-PHP源码


snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。

下面是它的一些特征:

1. 方便抓取网页的内容
2. 方便抓取网页的文字(去掉HTML代码)
3. 方便抓取网页的链接
4. 支持代理主机
5. 支持基本的用户/密码认证模式
6. 支持自定义用户agent,referer,cookies和header内容
7. 支持浏览器转向,并能控制转向深度
8. 能把网页中的链接扩展成高质量的url(默认)
9. 方便提交数据并且获取返回值
10.支持跟踪HTML框架(v0.92增加)
11.支持再转向的时候传递cookies

php使用Snoopy.class.php做http get post请求

1. [代码]通过get方法获取指定url内容

fetch($url); //获取所有内容 
echo $snoopy->results; //显示结果 
//可选以下 
$snoopy->fetchtext //获取文本内容(去掉html代码) 
$snoopy->fetchlinks //获取链接 
$snoopy->fetchform //获取表单 
?>

2. [代码]表单提交

submit($action,$formvars);//$formvars为提交的数组 
echo $snoopy->results; //获取表单提交后的 返回的结果 
//可选以下 
$snoopy->submittext; //提交后只返回 去除html的 文本 
$snoopy->submitlinks;//提交后只返回 链接 
?> 


伪装ip,伪装浏览器
cookies["PHPSESSID"] = 'fc106b1918bd522cc863f36890e6fff7'; //伪装sessionid 
$snoopy->agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98)"; //伪装浏览器 
$snoopy->referer = https://www.php1.cn/; //伪装来源页地址 http_referer 
$snoopy->rawheaders["Pragma"] = "no-cache"; //cache 的http头信息 
$snoopy->rawheaders["X_FORWARDED_FOR"] = "127.0.0.101"; //伪装ip 
$snoopy->submit($action,$formvars); 
echo $snoopy->results; 
?> 



submit($submit_url,$submit_vars); 
print $snoopy->results;

?>

3. [代码]使用代理

proxy_host = "my.proxy.host";
$snoopy->proxy_port = "8080";
// set browser and referer:
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$snoopy->referer = "http://www.jonasjohn.de/";
// set some cookies:
$snoopy->cookies["SessionID"] = '238472834723489';
$snoopy->cookies["favoriteColor"] = "blue";
// set an raw-header:
$snoopy->rawheaders["Pragma"] = "no-cache";
// set some internal variables:
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false;
// set username and password (optional)//
$snoopy->user = "joe";
snoopy->pass = "bloe";
// fetch the text of the website www.google.com:
if($snoopy->fetchtext("http://www.google.com"))
{ // other methods: fetch, fetchform, fetchlinks, submittext and submitlinks
// response code: print "response code: ".$snoopy->response_code."
\n"; // print the headers: print "Headers:
"; while(list($key,$val) = each($snoopy->headers)) { print $key.": ".$val."
\n"; } print "
\n"; // print the texts of the website: print "
".htmlspecialchars($snoopy->results)."
\n"; } else { print "Snoopy: error while fetching document: ".$snoopy->error."\n"; } ?>

www.phpzy.comtrue/php/40334.htmlTechArticlephp使用Snoopy.class.php做httpgetpost请求-PHP源码 snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。 下面是它的一些特征: 1. 方便抓取网页的内容 2. 方...

相关文章

PHP之友评论

今天推荐