Reputation: 489
Very novice level question. What's the easiest way of opening several websites one by one after reading site names from an external file. In the example below; I want to replace values of web URL from file and screemshot file name in same way.
Example script:
From selenium import webdriver
Driver=webdriver.ie(...driverpath)
Driver.get("facebook.com")
Driver.get_screenshot_as_file("facebook.png")
Driver.quit()
Upvotes: 0
Views: 1661
Reputation: 2015
Try this, I have used json for storing the websites, a simple text file will do as well
import json
from selenium.webdriver import Chrome
with open('path to json file', encoding='utf-8') as s:
data = json.loads(s.read())
for site in data['sites']:
driver = Chrome('path to chrome driver')
driver.get(data['sites'][site])
driver.get_screenshot_as_file(site + '.png')
driver.close()
json file
{
"sites": {
"facebook": "https://www.facebook.com/",
"google": "https://www.google.com/",
"wikipedia": "https://www.wikipedia.org/"
}
}
Upvotes: 1