I’m fairly new to coding with Python and I had some questions regarding Selenium:
So basically what I’m trying is:
-user inputs multiple links to different sites
-the script opens the first link and closes the browser afterwards and opens the next link
-the user only inputs for example ‘google.com’ but the browser automatically opens ‘http://google.com’ (thats the reason why I try to append the link and the ‘http’ variable)
but I always have the following error code: line 18, in <module> driver.get(url)
and Chrome opens a new tab with ‘data:,’ as the URL
JavaScript
x
19
19
1
from selenium import webdriver
2
from time import sleep
3
4
5
http = list()
6
http = ['http://']
7
8
input_1 = input('Site: ').split()
9
10
link = http.append(input_1)
11
12
driver = webdriver.Chrome(executable_path=r'C:...chromedriver.exe')
13
14
for url in link:
15
driver.set_window_size(1920, 1080)
16
driver.get(url)
17
sleep(4)
18
driver.quit()
19
Advertisement
Answer
Your logic/syntax is wrong. You have to fix the way you are attaching the ‘http://’ part. Following code is working for me:
from selenium import webdriver from time import sleep
JavaScript
1
12
12
1
http = 'http://'
2
input_1 = input('Site: ').split()
3
link = [http + site for site in input_1]
4
5
driver = webdriver.Chrome(executable_path=r'C:...chromedriver.exe')
6
7
for url in link:
8
driver.set_window_size(1920, 1080)
9
driver.get(url)
10
sleep(4)
11
driver.quit()
12