2

我正在尝试单击“添加到包”按钮,并且使用 selenium 它工作得很好,但是在使用 selenium-wire 和经过身份验证的代理服务器之后,虽然我仍然可以访问站点并单击所有其他按钮并且它可以工作,在单击此之后一什么事都没发生。我尝试了多个代理,甚至使用外部软件对其进行了测试,并在https://www.whatismyip.com/上检查了我的 ip 。
我还通过将代理添加到firefox,导航到页面并单击相同的按钮来手动测试代理,它可以工作。我第二天正在处理这个问题,我不知道我应该找到什么,是的,必须使用经过身份验证的代理。

代理的模块和定义:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from seleniumwire import webdriver as web

options = {
    'proxy': {
        'http': 'http://user:pass@IP:Port',
        'https': 'https://user:pass@IP:Port',
        'no_proxy': 'localhost,127.0.0.1'
    }
}

driver = web.ChromeDriver(seleniumwire_options=options)
wait = WebDriverWait(driver, c_default_wait)

这是单击按钮的代码:

try:
    #This actually finds the button (i do some staff on this page and it is loaded and clickible)
    buy_button = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div[3]/div[3]/div[2]/div/div/form/div[2]/button[1]") 
    print(buy_button.text)
except:
    driver.close()

while inbag == 0:
        try:
            checkout_button = wait.until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[1]/div[2]/div/div/div[4]/div/div/div/div/div/div/div/div/div/div[3]/div/button[2]")))
        except:
            buy_button.click()
        else:
            print(checkout_button.text)
            checkout_button.click()
            inbag = 1

这是重复的 bash 输出:

Traceback (most recent call last):
  File "%Repo_path%\env\lib\site-packages\seleniumwire\proxy\proxy2.py", line 91, in proxy_request
    conn.request(self.command, path, req_body, dict(req.headers))
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1262, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1308, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1257, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1028, in _send_output
    self.send(msg)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 968, in send
    self.connect()
  File "D:\Repos\BOOTS-BOT\env\lib\site-packages\seleniumwire\proxy\proxy2.py", line 368, in connect
    super().connect()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 1424, in connect
    super().connect()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 944, in connect
    self._tunnel()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 918, in _tunnel
    (version, code, message) = response._read_status()
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\http\client.py", line 267, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\socket.py", line 589, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out
Error making request

更新:
我们发现问题出在 CORS POLICY 上,我们将其修复如下:

  • 我们改成了 Chrome(上面已经改写了)
chrome_options.add_argument("--disable-web-security")

但不幸的是,我们在登录时遇到了类似的问题,浏览器报告错误:400 错误请求和错误:403 禁止访问

4

0 回答 0