Skip to content

Commit

Permalink
[update] 代理验证函数
Browse files Browse the repository at this point in the history
  • Loading branch information
jhao104 committed Mar 31, 2017
1 parent 5847bbe commit f382272
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Util/utilFunction.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
2016/11/25: 添加robustCrawl、verifyProxy、getHtmlTree
-------------------------------------------------
"""
import requests


# noinspection PyPep8Naming
Expand Down Expand Up @@ -55,3 +56,20 @@ def getHtmlTree(url, **kwargs):
}
html = requests.get(url=url, headers=header, timeout=30).content
return etree.HTML(html)


def validUsefulProxy(proxy):
"""
检验代理可以性
:param proxy:
:return:
"""
proxies = {"http": "http://{proxy}".format(proxy=proxy),
"https": "https://{proxy}".format(proxy=proxy)}
try:
# 超过30秒的代理就不要了
r = requests.get('https://www.baidu.com/', proxies=proxies, timeout=30, verify=False)
if r.status_code == 200:
return True
except Exception, e:
return False

0 comments on commit f382272

Please sign in to comment.