[小白求助] 爬取猫眼 top100,打印显示为空

2018-12-03 21:45:31 +08:00
 15874103329
源代码如下:

import requests
from requests.exceptions import RequestException

def get_one_page(url):
try:
response = requests.get(url)
if requests.status_codes == 200:
return response.text
return None
except RequestException:
return None

def main():
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3573.0 Safari/537.36'}
url = requests.get('https://www.hao123.com/', headers=headers)
html = get_one_page(url)
print(html)

if __name__ == '__main__':
main()
2120 次点击
所在节点    Python
6 条回复
F1024
2018-12-03 21:59:54 +08:00
网址都错了啊 兄弟
hly9469
2018-12-03 22:07:53 +08:00
@F1024 #1 哈哈哈哈哈哈
deepdark
2018-12-03 22:11:40 +08:00
@F1024 哈哈哈哈哈哈哈哈哈 hao123 还行
lanqing
2018-12-04 08:48:13 +08:00
找点教程看看吧
15874103329
2018-12-04 10:00:24 +08:00
额,网址之前是对的,后来换别的网址也是这样,不知道哪里出问题了
zh584728
2018-12-06 08:54:24 +08:00
requests.get 请求了两遍,第二遍肯定是 return None 啦

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/513982

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX