欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python requests設(shè)置代理的方法步驟

 更新時(shí)間:2020年02月23日 10:43:35   作者:丫丫博客  
這篇文章主要介紹了Python requests設(shè)置代理的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

指導(dǎo)文檔:
http://docs.python-requests.org/en/master/user/advanced/ 的Proxies
http://docs.python-requests.org/en/latest/user/advanced/ 的SSL Cert Verification

requests設(shè)置代理

import requests
proxies = {'http': 'http://localhost:8888', 'https': 'http://localhost:8888'}
url = 'http://www.baidu.com'
requests.post(url, proxies=proxies, verify=False) #verify是否驗(yàn)證服務(wù)器的SSL證書

執(zhí)行結(jié)果:

基于 selenium的代理設(shè)置:

from selenium import webdriver

proxy='124.243.226.18:8888'

option=webdriver.ChromeOptions()

option.add_argument('--proxy-server=http://'+proxy)

driver = webdriver.Chrome(options=option)

driver.get('http://httpbin.org/get')

python3.8 request proxy(代理)失效解決方案

在使用python3.8版本的時(shí)候,我們使用request庫的時(shí)候,可能會(huì)遇到

urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme None

下面這樣的錯(cuò)誤,這是游戲底層修改了url解析模式,導(dǎo)致proxy代理解析失敗導(dǎo)致的。

解決方案是:

如果不使用代理,那么就可以改成

proxies = {

"http": "",

"https": "",

}

request.get(url,proxies=proxies)

如果使用代理的話,就可以修改成:

proxies = {

"http":" http://127.0.0.1:1080",

"https":"https://127.0.0.1:1080",

}

需要注意的是,一定要寫成http://+ip+port這種形式,不能去掉前面的http://,否則就會(huì)產(chǎn)生錯(cuò)誤。

到此這篇關(guān)于Python requests設(shè)置代理的方法步驟的文章就介紹到這了,更多相關(guān)Python requests設(shè)置代理內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論