1

I have the following code:

 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")

The link is list of the urls, which I need to parse. First element of the link is okey but when second link opens;

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

How can I browse different links from an array?

1 Answer 1

4

You close your driver inside the for-loop, thus the second iteration can not work with it anymore.

Try using driver.close() after the for-loop:

driver = webdriver.Firefox()

for element in links:
    driver.do_something()

driver.close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.