学习python的第一天:requests库的基本使用

学习python的第一天
requests库的基本使用

import requests
r=requests.get(‘http://www.baidu.com’)
r.status_code
200------返回值为200,说明正常,若为404,就NOT FOUND了!

r.text------抓取信息
‘\r\n <meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge>

ç\x99¾åº¦ä¸\x80ä¸\x8bï¼\x8cä½\xa0å°±ç\x9f¥é\x81\x93
学习python的第一天:requests库的基本使用
æ\x96°é\x97» hao123 å\x9c°å\x9b¾ è§\x86é¢\x91 è´´å\x90§ <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>ç\x99»å½\x95 æ\x9b´å¤\x9a产å\x93\x81
\r\n’

r.encoding
‘ISO-8859-1’

r.apparent_encoding
‘utf-8’

r.encoding='utf-8’
r.text
‘\r\n <meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge>

百度一下,你就知道
学习python的第一天:requests库的基本使用
新闻 hao123 地图 视频 贴吧 <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录 更多产品

关于百度 About Baidu

©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号  学习python的第一天:requests库的基本使用

\r\n’

学习python的第一天:requests库的基本使用
r.encoding 从HTTP header中猜测的响应内容的编码方式
r.apparent_encoding 从内容中分析出的响应内容的编码方式(备选编码方式)
若header中不存在charset,则认为编码为ISO-8859-1

今日学习完毕,跟团支书聊了一会儿,碎觉!
2020.02.20 00:58