Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium挂起驱动程序。get()_Python_Linux_Selenium_Selenium Chromedriver - Fatal编程技术网

Python Selenium挂起驱动程序。get()

Python Selenium挂起驱动程序。get(),python,linux,selenium,selenium-chromedriver,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_

我正在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)

然后使用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)
class解析器():
定义初始化(自我、文字、登录凭据):
选项=选项()
option.add_参数(“--disable infobar”)
选项。添加参数(“开始最大化”)
option.add_参数(“--disable extensions”)
选项。添加参数(“--headless”)
option.add_experimental_选项(
“prefs”,{“profile.default\u content\u setting\u value.notifications”:2}
)
self.driver=webdriver.Chrome(
选项=选项,可执行路径='/usr/bin/chromedriver'
)
self.driver.set\u page\u load\u超时(20)
def重定向(自我、链接):
尝试:
self.driver.get(链接)
除TimeoutException外:
打印(“将停止在此加载页面”)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
parser=parser()
链接=[]
对于链接中的链接:
重定向(链接)
以下是中断后的回溯:

     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
self.driver.get(链接)
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/selenium/webdriver/remote/webdriver.py”,第330行,在get中
self.execute(Command.GET,{'url':url})
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/selenium/webdriver/remote/webdriver.py”,第316行,执行
响应=self.command\u executor.execute(driver\u command,params)
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/selenium/webdriver/remote/remote_connection.py”,第347行,在execute中
返回self.\u请求(命令信息[0],url,正文=数据)
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/selenium/webdriver/remote/remote\u connection.py”,第370行,在请求中
resp=self.\u conn.request(方法、url、body=body、headers=headers)
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/urllib3/request.py”,请求中第80行
方法,url,字段=字段,标题=标题,**urlopen\u
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site-packages/urllib3/request.py”,第171行,在request\u encode\u正文中
返回self.urlopen(方法,url,**额外\u kw)
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/urllib3/poolmanager.py”,urlopen中第330行
response=conn.urlopen(方法,u.request\u uri,**kw)
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/urllib3/connectionpool.py”,urlopen第672行
分块的,
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/urllib3/connectionpool.py”,第421行,在请求中
六、从(e,无)中提高
文件“”,第3行,从
文件“/home/ubuntu/.local/share/virtualenvs/Linux-scraper-Zulc4Pj0/lib/python3.6/site packages/urllib3/connectionpool.py”,第416行,请求
httplib_response=conn.getresponse()
getresponse中的文件“/usr/lib/python3.6/http/client.py”,第1346行
response.begin()
文件“/usr/lib/python3.6/http/client.py”,第307行,在begin中
版本、状态、原因=self.\u读取\u状态()
文件“/usr/lib/python3.6/http/client.py”,第268行,处于读取状态
line=str(self.fp.readline(_MAXLINE+1),“iso-8859-1”)
readinto中的文件“/usr/lib/python3.6/socket.py”,第586行
返回自我。将袜子重新放入(b)
键盘中断
有人能帮忙解决司机卡在车上的问题吗

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

     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