Selenium 挂在 driver.get() 上

Iks*_*zad 8 python linux selenium selenium-chromedriver

我在 Linux Mint 19.3 和远程服务器 Ubuntu 18.04.4 LTS 上使用 Python 3.7.6、Chrome 80.0.3987.122、chromedriver 80.0.3987.106 和 Selenium 4.0.0a3。
虽然在我本地的 Mint 上一切都工作得很好,但我无法在远程 Ubuntu 上运行该应用程序

在我的应用程序中的某个时刻,我运行 driver.get() 并且驱动程序似乎卡住了。我试图让驱动程序抛出 TimeoutException 像这样:

driver.set_page_loadtimeout(15)
Run Code Online (Sandbox Code Playgroud)

driver.implicitly_wait(15)
Run Code Online (Sandbox Code Playgroud)

然后使用js脚本停止加载,但是两次都没有抛出TimeoutException,我需要使用ctrl + c键盘中断来停止应用程序。

这是我的实现的一些示例代码:

class Parser():
def __init__(self, words, login_credentials):
    option = Options()

    option.add_argument("--disable-infobars")
    option.add_argument("start-maximized")
    option.add_argument("--disable-extensions")
    option.add_argument("--headless")

    option.add_experimental_option(
        "prefs", {"profile.default_content_setting_values.notifications": 2}
    )

    self.driver = webdriver.Chrome(
        options=option, executable_path='/usr/bin/chromedriver'
    )
    self.driver.set_page_load_timeout(20)

def redirect(self, link):
    try:
        self.driver.get(link)
    except TimeoutException:
        print("Would stop loading page here")


if __name__ == '__main__':
    parser = Parser()
    links = [<List of urls>]
    for link in links:
        parser.redirect(link)
Run Code Online (Sandbox Code Playgroud)

这是中断后的回溯:

     self.driver.get(link)
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 330, in get
    self.execute(Command.GET, {'url': url})
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 316, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 347, in execute
    return self._request(command_info[0], url, body=data)
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 370, in _request
    resp = self._conn.request(method, url, body=body, headers=headers)
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/request.py", line 80, in request
    method, url, fields=fields, headers=headers, **urlopen_kw
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/request.py", line 171, in request_encode_body
    return self.urlopen(method, url, **extra_kw)
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/poolmanager.py", line 330, in urlopen
    response = conn.urlopen(method, u.request_uri, **kw)
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/lib/python3.6/http/client.py", line 1346, in getresponse
    response.begin()
  File "/usr/lib/python3.6/http/client.py", line 307, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.6/http/client.py", line 268, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
KeyboardInterrupt
Run Code Online (Sandbox Code Playgroud)

谁能帮忙解决司机卡住的问题吗?

编辑:我想添加一点奇怪的事情,几天前脚本运行正常,但随着时间的推移,这些“冻结”开始发生,而无需对代码进行特定更改,现在甚至第一个重定向也冻结了。