pys.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:ProxyYourSpider 作者: rafacheng 项目源码 文件源码
def checkValidity(self, _type, proxy):
        proxyDict = {_type : _type + '://' + proxy}
        ua = UserAgent()
        headers = {'User-Agent' : ua.random}
        try:
            if _type == 'http':
                r = requests.get(self.http_test_url, proxies=proxyDict,\
                        headers=headers, timeout=2)
            else:
                r = requests.get(self.https_test_url, proxies=proxyDict,\
                        headers=headers, timeout=2)
        except Exception:
            return False
        soup = BeautifulSoup(r.text, 'lxml')
        try:
            retDict = eval(soup.find('body').text)
        except Exception:
            return False
        if proxy.split(':')[0] == retDict['origin']:
            return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号