JavaScript
x
20
20
1
#Import
2
from urllib.request import ProxyDigestAuthHandler, Request, urlopen
3
from bs4 import BeautifulSoup
4
from bs4.element import SoupStrainer
5
import requests
6
7
#PreInit
8
PROXY = {"https": "54.93.88.15:9300", "https": "165.22.81.30:38244", "https": "207.154.205.135:9999", "https": "88.198.26.145:8080", "https": "144.91.86.144:3128"}
9
url = "https://www.ebay.de/b/Laptops-Notebooks/175672/bn_1618754?LH_ItemCondition=7000&mag=1&rt=nc&_dmd=1&_sop=1"
10
req = Request(url, headers={"User-Agent": "Mozilla/5.0"}, proxies=PROXY)
11
webpage = urlopen(req).read()
12
13
#Init
14
with requests.Session() as c:
15
all_data = []
16
#Web init
17
soup = BeautifulSoup(webpage, "html5lib")
18
#Data collection...
19
print(shipping.text.strip())
20
The thing above is the relevant part to the error im getting when running the script. Where do i incorporate the “proxies” value? Help appreciated
Advertisement
Answer
You’re getting this error because there is no “proxies” argument in the constructor for a Request. There’s actually an example of a request using a proxy in the source code of the library you are using.
JavaScript
1
14
14
1
# Note assigning more than one value to a key in a dict will result in only the final value being assigned to the key
2
PROXY = {"https": "54.93.88.15:9300"}
3
url = "https://www.ebay.de/b/Laptops-Notebooks/175672/bn_1618754?LH_ItemCondition=7000&mag=1&rt=nc&_dmd=1&_sop=1"
4
req = Request(url, headers={"User-Agent": "Mozilla/5.0"})
5
6
# Create proxy ProxyHandler
7
proxy_support = urllib.request.ProxyHandler(PROXY)
8
# Create opener
9
opener = urllib.request.build_opener(proxy_support)
10
# Install opener
11
urllib.request.install_opener(opener)
12
13
webpage = urllib.request.urlopen(req)
14