1

I am trying to click on one link from a list of links, wait one second (not added yet) and then click on the next link. Using selenium and bs4. This is my code:

links = ['https://www.bing.com', 'https://www.google.com', 'https://www.yahoo.com']
for url in links:
    url = "'"+url+"'"
    print(url,'\n')
    browser = webdriver.Firefox
    browser.get(url)

and this is the error I am getting:

Traceback (most recent call last):
  File "C:/Users/SK/PycharmProjects/untitled/linkedin_bot.py", line 38, in <module>
    browser.get(url)
TypeError: get() missing 1 required positional argument: 'url'

What exactly am I doing wrong and how to solve it? Thanks

Andrew Regan
  • 5,087
  • 6
  • 37
  • 73
skeitel
  • 271
  • 2
  • 6
  • 17
  • You're creating a new browser instance for *every single request*? Here's why you might want to change that: http://stackoverflow.com/a/35116310/954442 – Andrew Regan Feb 06 '16 at 12:41

2 Answers2

1

You need to change browser = webdriver.Firefox to browser = webdriver.Firefox(). As it is, when you call browser.get(url), it is expecting a webdriver.Firefox instance as the first argument and a url as the second argument. When you include the parentheses, you are creating an instance of webdriver.Firefox and Python automatically gives it as the first argument.

zondo
  • 19,901
  • 8
  • 44
  • 83
0

The main problem is that the "url" variable name is the same as the "url" in the for loop. Try renaming the variable.

Here is the amended code. I have used Chrome as the driver, but you can use Firefox or any other driver. Remember to change the executable path of the driver to match your situation.

from selenium import webdriver

import time

browser = webdriver.Chrome(executable_path='C:\Chrome\chromedriver.exe')

links = ['https://www.bing.com', 'https://www.google.com', 'https://www.yahoo.com']
for url in links:
    urls = "'"+url+"'"
    print(urls,'\n')
    browser.get(url)
    time.sleep(1)
Ben
  • 26
  • 1
  • 4