3.2 网络数据获取
1. 获取网页
r = requests.get(url) r.status_code
r.text r.content r.json() r.encoding = ‘utf8’
例子
a.假设获取的是二进制文件,则可以借鉴如下方法保存数据:
- r = requests.get('http://www.baidu.com/img/bd_logo1.png',headers=headers)
- with open('c:\\test\\baidu.png', 'wb') as fp:
- fp.write(r.content)
2.解析网页
Beautifulsoup库 https://www.crummy.com/software/BeautifulSoup/bs4/doc/