Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 webdriver错误_Python_Python 2.7_Selenium_Python 3.x_Selenium Webdriver - Fatal编程技术网

Python-运行数小时后出现Selenium webdriver错误

Python-运行数小时后出现Selenium webdriver错误,python,python-2.7,selenium,python-3.x,selenium-webdriver,Python,Python 2.7,Selenium,Python 3.x,Selenium Webdriver,我在云计算机(AWS 1GB实例)上运行一个机器人,我使用的是selenium webdriver+pyvirtualdisplay 我在一个循环中做一些重复的事情,它将迭代50000次。在运行我的脚本后,它在1016(50000中)停止工作。错误是 Traceback (most recent call last): File "automation.py", line 108, in <module> main() File "automation.py", li

我在云计算机(AWS 1GB实例)上运行一个机器人,我使用的是selenium webdriver+pyvirtualdisplay

我在一个循环中做一些重复的事情,它将迭代50000次。在运行我的脚本后,它在1016(50000中)停止工作。错误是

Traceback (most recent call last):
  File "automation.py", line 108, in <module>
    main()
  File "automation.py", line 10, in main
    driver = webdriver.Firefox()
  File "/home/eric/work/lak/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "/home/eric/work/lak/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "/home/eric/work/lak/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
    self._wait_until_connectable()
  File "/home/eric/work/lak/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 105, in _wait_until_connectable
    self.profile.path, self._get_firefox_output()))
selenium.common.exceptions.WebDriverException: Message: 'Can\'t load the profile. Profile Dir: /tmp/tmp7CXXn1 Firefox output: \n(process:22693): GLib-CRITICAL **: g_slice_set_config: assertion \'sys_page_size == 0\' failed\nXlib:  extension "RANDR" missing on display ":1213".\n1406467599310\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/modules/addons/XPIProvider.jsm: ["XPIProvider"]\n1406467599312\taddons.manager\tDEBUG\tLoaded provider scope for resource://gre/modules/LightweightThemeManager.jsm: ["LightweightThemeManager"]\n1406467599314\taddons.xpi\tDEBUG\tstartup\n1406467599339\taddons.xpi\tDEBUG\tcheckForChanges\n1406467599351\taddons.xpi\tDEBUG\tNo changes found\nSystem JS : ERROR chrome://browser/content/browser.js:12132 - SyntaxError: function statement requires a name\n 
System JS : ERROR (null):0 - out of memory\n
System JS : ERROR (null):0 - out of memory\n
System JS : ERROR (null):0 - out of memory\n
System JS : ERROR (null):0 - out of memory\n
System JS : ERROR (null):0 - out of memory\n
System JS : ERROR (null):0 - out of memory\n
System JS : ERROR (null):0 - out of memory\n' 
供您参考这里是我的代码看起来像

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from pyvirtualdisplay import Display

display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
driver.maximize_window()

url = 'some url'

for i in range(1,50000):
    driver.get(url)
    #somestuff
    i+=1

从错误日志来看,您似乎正在使用unix风格

我过去也犯过同样的错误。 显然,我们可以看到系统无法提供足够的内存

运行
top
命令,查看可用内存是否足够。如果没有,那么杀死一些不必要的进程

这应该行得通

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from pyvirtualdisplay import Display

display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
driver.maximize_window()

url = 'some url'

for i in range(1,50000):
    driver.get(url)
    #somestuff
    i+=1