Pythonでスクレイピングする際にrequestsにプロキシ設定をすると以下のエラーが起きます。
前までは問題なかったのですが、どこが問題なのでしょうか?プロキシ設定を指定しければ問題なく動作します。
<試したこと>
リンク先を複数試した。
proxiesの内容を複数試した。
時間を1日ほどおいた。
Colab環境なのでJupyter labも試した。
環境端末を変更した。
<エラー文>
ConnectionRefusedError Traceback (most recent call last)
MaxRetryError Traceback (most recent call last)
NewConnectionError Traceback (most recent call last)
ProxyError Traceback (most recent call last)
ProxyError: HTTPSConnectionPool: Max retries exceeded
<追記>
コード内の追記コードを使用して画像のようなjsonファイルを読み込んでプロキシ設定をしていました。前は問題がなかったのですが、同じようにしてもエラーが起きるようになってしまいました。
Python
1import requests 2from bs4 import BeautifulSoup 3 4URL = "https://www.cman.jp/network/support/go_access.cgi" 5USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36" 6 7proxies = { 8 'http':'https://39.108.154.193:22', 9 'https':'https://39.108.154.193:22' 10} 11 12headers = {'User-Agent': USER_AGENT} 13 14resp = requests.get(URL, proxies=proxies, headers=headers, timeout=10) 15resp.encoding = 'utf8' 16soup = BeautifulSoup(resp.text, 'html.parser') 17 18ip = soup.find(class_ = "outIp").text 19print(ip) 20#<追記> 21json_open = open(FILE_PATH, 'r') 22proxy_list = json.load(json_open) 23proxy_info = random.choice(proxy_list) 24ip = proxy_info['ip'] 25port = proxy_info['port'] 26protocol = proxy_info['protocol'] 27proxy = protocol + '://' + str(ip) + ':' + port 28proxies = { 'http':proxy, 29'https':proxy}

あなたの回答
tips
プレビュー