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
评论列表
文章目录