Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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,从数组中获取链接_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python selenium,从数组中获取链接

Python selenium,从数组中获取链接,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我有以下代码: driver = webdriver.Firefox() for element in links: driver.get(element) html = driver.page_source soup = BeautifulSoup(html, 'html.parser') #driver.switchTo().window() driver.close() date = soup.find_all("td", {"id":

我有以下代码:

 driver = webdriver.Firefox()

 for element in links:
    driver.get(element)
    html = driver.page_source
    soup = BeautifulSoup(html, 'html.parser')
    #driver.switchTo().window()
    driver.close()
    date = soup.find_all("td", {"id": "utime"})
    title = soup("title")
链接是URL的列表,我需要对其进行解析。链接的第一个元素正常,但当第二个链接打开时

Traceback (most recent call last):
File "/home/Version01.py", line 10, in <module>
driver.get(element)
File "/usr/local/lib/python2.7/dist-packages
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver     /remote/webdriver.py", line 199, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver /remote/remote_connection.py", line 395, in execute
  return self._request(command_info[0], url, body=data)
 .......
File "/usr/lib/python2.7/httplib.py", line 778, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 571, in   create_connection
raise err
socket.error: [Errno 111] Connection refused
回溯(最近一次呼叫最后一次):
文件“/home/Version01.py”,第10行,在
驱动程序。获取(元素)
文件“/usr/local/lib/python2.7/dist-packages
self.execute(Command.GET,{'url':url})
文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,执行中的第199行
响应=self.command\u executor.execute(driver\u command,params)
文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py”,执行中第395行
返回self.\u请求(命令信息[0],url,正文=数据)
.......
文件“/usr/lib/python2.7/httplib.py”,第778行,在connect中
self.timeout,self.source\u地址)
文件“/usr/lib/python2.7/socket.py”,第571行,在create_connection中
提出错误
socket.error:[Errno 111]连接被拒绝

如何从数组中浏览不同的链接?

在for循环中关闭
驱动程序
,因此第二次迭代无法再使用它

在for循环之后尝试使用
driver.close()

driver = webdriver.Firefox()

for element in links:
    driver.do_something()

driver.close()

在for循环中关闭
驱动程序
,因此第二次迭代无法再使用它

在for循环之后尝试使用
driver.close()

driver = webdriver.Firefox()

for element in links:
    driver.do_something()

driver.close()