网络编程
位置:首页>> 网络编程>> Python编程>> Python3 requests模块如何模仿浏览器及代理

Python3 requests模块如何模仿浏览器及代理

作者:阿久丶xin  发布时间:2023-04-05 06:50:44 

标签:Python,requests,模块,代理

requests是使用Apache2 licensed 许可证的HTTP库。

用python编写。

比urllib2模块更简洁。

Request支持HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动响应内容的编码,支持国际化的URL和POST数据自动编码。

在python内置模块的基础上进行了高度的封装,从而使得python进行网络请求时,变得人性化,使用Requests可以轻而易举的完成浏览器可有的任何操作。

代码如下


import requests

def xiaodai():
 url = 'http://erge1998.cn/'

proxies = {
   'http': 'http://149.28.38.64:1081',
   'https': 'https://149.28.38.64:1081'
 }

headers = {
   'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'
 }

try:
   response = requests.get (url, headers=headers, proxies=proxies)
   print(response.text)
 except Exception as e:
   print(e)

if __name__ == '__main__':
 xiaodai()

结果

Python3 requests模块如何模仿浏览器及代理

来源:https://www.cnblogs.com/laod/p/13098730.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com