在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python/ python:代碼訪問weixin.sogou.com的時候會出現(xiàn)驗證碼,但是瀏

python:代碼訪問weixin.sogou.com的時候會出現(xiàn)驗證碼,但是瀏覽器打開就不會

自己寫了個程序抓取weixin.sogou.com的數(shù)據(jù),時不時就出現(xiàn)驗證碼。
但是,當我使用瀏覽器打開weixin.sogou.com的時候,并沒有出現(xiàn)驗證碼。
難道搜狗不是根據(jù)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:
                    # 判斷是否出現(xiàn)驗證碼,出現(xiàn)的時候,有個切換IP的函數(shù)會執(zhí)行
                    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
回答
編輯回答
懷中人

檢測一下 UA

2018年7月8日 06:57