python爬虫设置代理ip

python爬虫设置代理ip,第1张

一、requests
import requests

ip = '127.0.0.1:7890'
proxies = {
    'http': 'http://' + ip,
    'https': 'http://' + ip,
}

res = requests.get('https://www.httpbin.org/ip',proxies=proxies)
print(res.json())
二、selenium
from selenium import webdriver

chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument('--proxy-server=http://127.0.0.1:7890')

wd = webdriver.Chrome(chrome_options=chromeOptions)
wd.get('http://httpbin.org/ip')

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/801844.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-07
下一篇 2022-05-07

发表评论

登录后才能评论

评论列表(0条)

保存