很抱歉,您的电脑或所在的局域网络有异常的访问,此刻我们无法响应您的请求.

Python020

很抱歉,您的电脑或所在的局域网络有异常的访问,此刻我们无法响应您的请求.,第1张

目前,当某个IP段在短时间内向百度发出大量连接请求,即会受到百度局域网异常访问屏蔽策略的限制。

有两个方法可以解决:

1.PHP抓取页面受限的破解方法

在使用PHP抓取百度知道问题页时,由于PHP程序抓取速度过快,导致被屏蔽,采用以下的方式解决

抓取页面需采用fsockopen方式,使用file_get_contents无法设置请求头

fsockopen函数的使用方法请自行查阅,例子中的geturlcont函数为自定义函数,核心即为fsockopen,geturlcont函数的原型

geturlcont($url, $referer = "" ,$cookie),$url为待抓取的页面的url,$referer为传递的referer参数(主要用于防止抓到的是百度首页),$cookie为重要的一个参数,用于破解局域网异常访问屏蔽功能

2.Chrome扩展直接跳转方案

在另一个程序中,不需要抓取页面内容,但会同时打开数十页的百度页面,同样可能会造成短时间内请求过多导致的屏蔽,解决方法是通过Chrome扩展的js注入功能实现

附(百度屏蔽页的代码):

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>百度--您的访问出错了</title>

<style>

body{text-align:centermargin-top:3px}

#wrap{width:650pxtext-align:leftmargin:auto}

#logo{float:leftmargin:0 3px 0 0}

#logo img{border:0}

#title{float:leftwidth:510px}

#intitle{margin:20px 0 0 0background-color:#e5ecf9width:100%font-weight:boldfont-size:14pxpadding:3px 0 4px 10px}

#content{clear:leftpadding-top:60pxline-height:200%}

#vf{margin-top:10px}

#vf img{float:leftborder:1px solid #000}

#kw{font:16px Verdanaheight:1.78empadding-top:2px}

#vf form{float:leftmargin:12px 0 0 5pxpadding:0}

#ft{text-align:center}

#ft,#ft a{color:#666font-size:14px}

</style>

</head>

<body>

<div id="wrap">

<div id="logo"><a href="http://www.baidu.com"><img alt="到百度首页" title="到百度首页" src="http://www.baidu.com/img/logo-yy.gif" width="137" height="46"></a></div>

<div id="title"><div id="intitle">您的访问出错了</div></div>

<div id="content">很抱歉,您的电脑或所在的局域网络有异常的访问,此刻我们无法响应您的请求。 <br>请输入以下验证码,即可恢复使用。</div>

<div id="vf">

<img src="http://verify.baidu.com/cgi-bin/genimg?9D5771ED69F27050263223420F7043C211B95E2D3616825774FF64E3FEF61920E3089D79E454888755B8F3AFDF124C9C74A34C4DDFAFD27827B3512B437BE76043" width="120" height="40">

<form action="http://verify.baidu.com/verify">

<input type="hidden" name="url" value="http://zhidao.baidu.com/question/519848902?oldq=1&vf_tf=1">

<input type="hidden" name="vcode" value="9D5771ED69F27050263223420F7043C211B95E2D3616825774FF64E3FEF61920E3089D79E454888755B8F3AFDF124C9C74A34C4DDFAFD27827B3512B437BE76043">

<input type="hidden" name="id" value="1359359285">

<input type="hidden" name="di" value="530e060fe3c68f3d">

<input type="text" size="6" maxlength="10" name="verifycode" id="kw">

<input type="submit" value="提交">

</form>

</div>

<div style="clear:leftheight:90px"></div>

<div id="ft">© 2012 Baidu <a href="http://www.baidu.com/duty/index.html">免责声明</a></div>

</div>

<script>

(function(){

var rfr = window.document.location.href,

p = encodeURIComponent(rfr),

img = new Image(),

imgzd = new Image(),

re = /\/vcode\?http:\/\/(\S+)\.baidu/ig,r=""

img.src = "http://nsclick.baidu.com/v.gif?pid=201&pj=vcode&path="+p+"&t="+new Date().getTime()

r = re.exec(rfr)

if(r&&r[1]){imgzd.src = "http://"+r[1]+".baidu.com/v.gif?fr=vcode&url="+p+"&t="+new Date().getTime()}

})()

</script>

</body>

</html>

打开你所要提取URL链接的网页,点击“网页另存为”(google浏览器)。这里存为“22”,记得是存为网页,如:“22.html”。

用“Notepad++文本编辑器“打开”22.html“。找到你所要提取的URL链接,根据URL链接的共同部分提取出来。

然后按CTRL+F查找,输入共同部分,如图。点击”在当前文件中查找“。就会在编辑页面的下面出现所有符合规则的下载地址,以行为单位,选中并复制。

将其黏贴到excel表格中,调整对应好,选中内容所在的表格列,选择“数据”菜单栏的“分列”。就会弹出如下的对话框,选择第一个选项“分隔符号”,点击下一步。

根据内容里面所含的特征,让其能提取你想要的URL链接。这里是可以通过(单引号“),就可以提取出我们要URL链接,那么在“分隔符号”中的最后一项“其他(o)”中输入(”),点击完成即可。

内容已经被分开了,而且在不同的单元格里面。整理,删掉我们不要的内容,最后得出的就是我们要的“URL链接”。

新建一个js文件,内容如下:

(function ($) {

$.getUrlParam = function(name)

{

var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)")

var r = window.location.search.substr(1).match(reg)

if (r!=null) return unescape(r[2])return null

}

}) (jQuery)

在要获取url参数的页面导入这个js,想要获取参数,就这样写:

var name = $.getUrlParam("name")

$.getUrlParam("name")的参数name就是url里面的参数名称。