requests使用代理访问国外网站

安装shadowsocksr并启动, 端口号默认1080

python代码实现:

import requests
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36'
}
proxies = {
    "http": "socks5://127.0.0.1:1080",
    'https': 'socks5://127.0.0.1:1080'
}

url = 'https://www.google.com/search?q=python'
res = requests.get(url, headers=headers, proxies=proxies)

猜你喜欢

转载自blog.csdn.net/shuishou07/article/details/82251447