requests简单爬取网站数据

用requests爬取数据
import requests,json
def renren(url,headers):
response=requests.get(url,headers=headers)
res_text=response.text
with open(‘renren.html’,’wb’) as ff:
ff.write(res_text)
if name==’main‘:
url=’xxxx’
headers={
‘xxxx’
}
renren(url,headers)
知识点:
《1》requests 中的requets.content 是bytes 类型 相当于reponse.read()
《2》requests.text 相当于 request.read(),decode(‘utf-8’)

《3》 出现maxinum number of open connections reached
重启自己的自己的代理服务器就好了,原因是其他人攻击破解造成的

猜你喜欢

转载自blog.csdn.net/chengjintao1121/article/details/81778561