|
代码:
# -*- coding:utf-8 -*-
import requests
import json
def get_one_page(url,headers):
resp**e = requests.get(url,headers)
print(resp**e.cookies)
print(resp**e.status_code)
print(resp**e.text)
print(type(resp**e.text))
print(resp**e.json)
print(type(resp**e.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 - conditi** - client - id': '0f286fdf - ae53 - 4784 - 9610 - 56f5b068a872'
}
url = 'https://www.toutiao.com/a6602782094278001159/'
get_one_page(url,headers)
运行结果:
C:\Users\Administrator\PycharmProjects\requestsprider\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/requestsprider/venv/test.py
<RequestsCookieJar[]>
200
<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta http-equiv=X-UA-Compatible content="ie=edge"><link rel="shortcut icon" href=//s3a.pstatp.com/toutiao/resource/ntoutiao_web/static/image/favicon_8e9c9c7.ico type=image/x-icon><title>今日头条</title></head><body><p></p></body></html>
<class 'str'>
<bound method Resp**e.json of <Resp**e [200]>>
<class 'method'>
Process finished with exit code 0
这个是为什么??网页源代码为什么为空?高手帮看一下。谢谢!
|
|