为什么获取代码为空??

2018-09-20 09:54:10 +08:00
 happykjoy

代码: #!/usr/bin/env python

-- coding:utf-8 --

import requests import json

def get_one_page(url,headers):

response = requests.get(url,headers)
print(response.cookies)
print(response.status_code)
print(response.text)
print(type(response.text))
print(response.json)
print(type(response.json))

if name == 'main': headers={ 'accept': 'text / html, application / xhtml + xml, application / xml;q = 0.9, image / webp, image / apng, * / *;q = 0.8', 'accept - encoding': 'gzip, deflate', 'accept - language': 'zh - CN', 'cache - control': 'max - age = 0', 'dnt': '1', 'upgrade - insecure - requests': '1', 'user - agent': 'Mozilla / 5.0(Windows NT 6.1) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 61.0.3163.79 Safari / 537.36 Maxthon / 5.2.3.3000', 'x - devtools - emulate - network - conditions - client - id': '0f286fdf - ae53 - 4784 - 9610 - 56f5b068a872' } url = 'https://www.toutiao.com/a6602782094278001159/' get_one_page(url,headers)

运行结果: <RequestsCookieJar[]> 200

<meta charset="UTF-8"><meta content="width=device-width,initial-scale=1" name="viewport"><meta content="ie=edge" http-equiv="X-UA-Compatible"><link href="//s3a.pstatp.com/toutiao/resource/ntoutiao_web/static/image/favicon_8e9c9c7.ico" rel="shortcut icon" type="image/x-icon"><title>今日头条</title>

<class 'str'> <bound method Response.json of <Response [200]>> <class 'method'>

为什么运行后代码为空,什么原因,网站屏蔽了吗???高手帮忙看一下。谢谢。

2648 次点击
所在节点    Python
4 条回复
iSecret
2018-09-20 10:23:37 +08:00
爬今日头条需要用到 PhantomJS。
NoString
2018-09-20 10:30:06 +08:00
js 渲染的界面得先拿 phantomJS 运行完再..
misaka19000
2018-09-20 11:29:46 +08:00
请把代码格式化好再发
happykjoy
2018-09-20 13:02:17 +08:00
好的,谢谢各位回复。

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

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

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

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

© 2021 V2EX