欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

【python】urllib和urllib3,requests 简要概括---笔记

发布时间:2023/12/20 python 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【python】urllib和urllib3,requests 简要概括---笔记 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
'''urllib和urllib3,requestsurl:协议://存放资源的地址(域名)/具体的资源https://bj.lianjia.com/zufang/dghfjhsjdf648.htmlurllib.request 用来发出请求urllib.parseurllib.request.urlopen(str) --->response对象request= urllib.request.Request(url,data,headers)urllib.request.urlopen(request) --->response对象从response中获取信息response.read() ----> 字节信息要对信息进行解码:response.read().decode('utf-8')''' import urllib.request import urllib.parse# response = urllib.request.urlopen('https://bj.lianjia.com/zufang/BJ2319485348977049600.html?nav=0') url = 'https://bj.lianjia.com/zufang/BJ2319485348977049600.html'header = {}header['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'data = {} data['nav'] = 0 data = urllib.parse.urlencode(data).encode('utf-8')# 创建请求对象 request = urllib.request.Request(url, data, header) response = urllib.request.urlopen(request) content = response.read() # print(content)print(content.decode('utf-8'))# urllib3 requests import urllib3 import requests# urllib3 requests # xpath beautifulsoup # get与post请求 http的请求方式 restful

 

总结

以上是生活随笔为你收集整理的【python】urllib和urllib3,requests 简要概括---笔记的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。