Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import json
- import time
- import os
- import pandas as pd
- from selenium import webdriver
- # Load Chrome Driver
- CHROMEDRIVER_PATH = 'C:/Users/rgraham_adm/Desktop/WebScraper2020/chromedriver.exe'
- # ------ changes ------
- # Names to Be Renamed - This is referenced in the renaming loop
- newNames = 'C:/Users/rgraham_adm/Desktop/RedditScript/Forms/NewNames.csv'
- with open(newNames, 'r') as f: # Removed quotes around newNames variable - mb
- reader = csv.reader(f)
- newNameList = list(reader)
- # ------ /changes ------
- appState = {
- "recentDestinations": [
- {
- "id": "Save as PDF",
- "origin": "local",
- "account": ""
- }
- ],
- "selectedDestinationId": "Save as PDF",
- "version": 2
- }
- downloadPath = 'C:/Users/rgraham_adm/Desktop/RedditScript/Forms'
- profile = {'printing.print_preview_sticky_settings.appState': json.dumps(appState),
- 'savefile.default_directory': downloadPath}
- options = webdriver.ChromeOptions()
- options.add_experimental_option('prefs', profile)
- options.add_argument('--kiosk-printing')
- driver = webdriver.Chrome(CHROMEDRIVER_PATH, chrome_options=options)
- with open('C:/Users/rgraham_adm/Desktop/RedditScript/Test.csv') as example_file:
- example_reader = csv.reader(example_file)
- for row in example_reader:
- driver.get(row[0]), time.sleep(5), driver.execute_script('window.print();')
- driver.quit()
- for index, item in enumerate(os.listdir(downloadPath)):
- print(f'{downloadPath}\{item}', f'{downloadPath}\{str(newNameList[index][0])}.pdf') # Adapted this code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement