forked from jhao104/proxy_pool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add proxy getter kuaidaili daili66 youdaili
- Loading branch information
Showing
5 changed files
with
93 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
------------------------------------------------- | ||
File Name: __init__.py.py | ||
Description : | ||
Author : JHao | ||
date: 2016/11/25 | ||
------------------------------------------------- | ||
Change Activity: | ||
2016/11/25: | ||
------------------------------------------------- | ||
""" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
------------------------------------------------- | ||
File Name: utilFunction.py | ||
Description : 工具函数 | ||
Author : JHao | ||
date: 2016/11/25 | ||
------------------------------------------------- | ||
Change Activity: | ||
2016/11/25: 添加robustCrawl、verifyProxy、getHtmlTree | ||
------------------------------------------------- | ||
""" | ||
|
||
|
||
# noinspection PyPep8Naming | ||
def robustCrawl(func): | ||
def decorate(*args, **kwargs): | ||
try: | ||
return func(*args, **kwargs) | ||
except Exception as e: | ||
print u"sorry, 抓取出错。错误原因:" | ||
print e | ||
|
||
return decorate | ||
|
||
|
||
def verifyProxy(proxy): | ||
""" | ||
检查代理格式 | ||
:param proxy: | ||
:return: | ||
""" | ||
import re | ||
verify_regex = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d{1,4}" | ||
return True if re.findall(verify_regex, proxy) else False | ||
|
||
def getHtmlTree(url, **kwargs): | ||
""" | ||
获取html树 | ||
:param url: | ||
:param kwargs: | ||
:return: | ||
""" | ||
import requests | ||
from lxml import etree | ||
html = requests.get(url=url).content | ||
return etree.HTML(html) | ||
|
Binary file not shown.