python微信验证码_python:代码访问weixin.sogou.com的时候会出现验证码,但是浏览器打开就不会...

自己写了个程序抓取weixin.sogou.com的数据,时不时就出现验证码。

但是,当我使用浏览器打开weixin.sogou.com的时候,并没有出现验证码。

难道搜狗不是根据IP来判断的吗?

代码:

def __weixin_search(self, keyword, cur_page, start_date, end_date, timeout=30):

html = None

while True:

try:

if self.__cookie is None:

self.__set_cookie(timeout=timeout)

if isinstance(keyword, types.UnicodeType):

keyword = keyword.encode('utf-8')

url = "http://weixin.sogou.com/weixin?type=2&s_from=input&ie=utf8&_sug_=n&_sug_type_=&query="

url += urllib2.quote(keyword)

headers = {

"User-Agent": random.choice(USER_AGENTS),# 随机

"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",

"Accept-Language": "zh-CN,zh;q=0.8",

"Accept-Encoding": "gzip, deflate, sdch",

"DNT": "1",

"Connection": "keep-alive",

"Cookie": self.__cookie

}

r = requests.get(url=url, headers=headers, timeout=timeout)

html = r.text.encode('ISO-8859-1')

if html is None or html.find(u'seccodeInput') is not -1:

# 判断是否出现验证码,出现的时候,有个切换IP的函数会执行

self.__cookie = None

time.sleep(1)

else:

t = HTMLParser.HTMLParser()

return t.unescape(html)

except Exception as ex:

#print_msg(msg=traceback.format_exc(), save_to_log=True)

pass

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值