Commit faa5455c authored by 李小芳's avatar 李小芳

add

parent fa1d3fcd
...@@ -91,8 +91,11 @@ class CrawlerMain(object): ...@@ -91,8 +91,11 @@ class CrawlerMain(object):
try: try:
requests_res = requests.get(url, headers=self.headers, allow_redirects=False, timeout=10) requests_res = requests.get(url, headers=self.headers, allow_redirects=False, timeout=10)
# 打印状态码 # 打印状态码
page_obj = etree.HTML(requests_res.text) if requests_res:
return page_obj, url page_obj = etree.HTML(requests_res.text)
return page_obj, url
else:
return None
except ReadTimeout: except ReadTimeout:
print('timeout') print('timeout')
return None, None return None, None
...@@ -119,8 +122,11 @@ class CrawlerMain(object): ...@@ -119,8 +122,11 @@ class CrawlerMain(object):
.format(query, page) .format(query, page)
try: try:
requests_res = requests.get(url, headers=self.headers, allow_redirects=False, timeout=10) requests_res = requests.get(url, headers=self.headers, allow_redirects=False, timeout=10)
res_json = requests_res.json() if requests_res:
return res_json res_json = requests_res.json()
return res_json
else:
return None
except ReadTimeout: except ReadTimeout:
print('超时,执行下一个请求') print('超时,执行下一个请求')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment