I'm sorry if there was such a topic but I could not find an answer. So, let's start: someone created such a code for me, but unfortunately he did not tell me how to run it and the mess itself and not write back. I tried to solve the problem myself but unfortunately my knowledge is not yet at this level. Well, when I try to fire the code in VSC I see such a mistake
c:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts>main.py
dane.xlsx
Traceback (most recent call last):
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts\main.py",line 21, in <module>
if __name__ == "__main__": main()
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\Scripts\main.py", line 8, in main
xl = pd.ExcelFile(input("dane.xlsx"))
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\io\excel.py", line 394, in __init__
self.book = xlrd.open_workbook(self._io)
File "C:\Users\XXX\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlrd\__init__.py", line 116, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory:
Here I give the code of 2 files, maybe there is a mistake in them: main.py
from wp import wp
import time
import pandas as pd
from selenium import webdriver
def main():
chromedriver = "chromedriver.exe"
xl = pd.ExcelFile(input("C:\Praca\dane.xlsx"))
# Print the sheet names
driver = webdriver.Chrome(executable_path=chromedriver)
# Load a sheet into a DataFrame by name: df1
df1 = xl.parse('Sheet1')
for data in df1.index:
_wp = wp(driver,df1['Strona'][data])
_wp._login()
_wp._send_data(df1['Tytul'][data],df1['Tresc'][data],df1['Data'][data],df1['Logo'][data],df1['Medium'][data],df1['Link'][data],df1['LinkA'][data])
if __name__ == "__main__": main()
wp.py
from datetime import datetime
import time
def get_time():
return str(datetime.now().strftime('[%H:%M:%S] '))
class wp():
def __init__(self,driver,base_url):
self.base_url = base_url
self.login = "xxx"
self.password = "xxx"
self.driver = driver
def _login(self):
self.driver.get(self.base_url+"/wp-login.php")
self.driver.find_element_by_id("user_login").send_keys(self.login)
self.driver.find_element_by_id("user_pass").send_keys(self.password)
self.driver.find_element_by_id("wp-submit").click()
def _send_data(self,title,content,date,logo,medium,link,linka):
self.driver.get(self.base_url+"/wp-admin/post-new.php")
self.driver.find_element_by_id("title").send_keys(title)
self.driver.find_element_by_id("content").send_keys(content)
self.driver.execute_script("document.getElementsByClassName('edit-timestamp hide-if-no-js')[0].click();")
date = date.split(".")
if date[1][0:1] == "0": date[1] = date[1][1:2]
self.driver.find_element_by_id("jj").send_keys(date[0])
self.driver.find_element_by_xpath('//*[@id="mm"]/option['+date[1]+']').click()
self.driver.find_element_by_id("aa").send_keys(date[2])
self.driver.execute_script("document.getElementsByClassName('save-timestamp hide-if-no-js button')[0].click();")
self.driver.execute_script("document.getElementById('set-post-thumbnail').click();")
self.driver.execute_script("document.getElementById('media-search-input').value='"+medium+"';")
time.sleep(1)
self.driver.execute_script("document.getElementsByClassName('thumbnail')[0].click();")
self.driver.execute_script("document.getElementsByClassName('button media-button button-primary button-large media-button-select')[0].click();")
self.driver.execute_script("document.getElementById('insert-media-button').click();")
self.driver.execute_script("document.getElementsByClassName('search')[1].value='"+logo+"';")
time.sleep(1)
self.driver.execute_script("document.getElementsByClassName('attachments ui-sortable ui-sortable-disabled')[1].getElementsByClassName('thumbnail')[0].click();")
time.sleep(1)
self.driver.execute_script("document.getElementsByClassName('media-sidebar visible')[0].getElementsByTagName('input')[1].value='"+link+"';")
self.driver.execute_script("document.getElementsByClassName('media-sidebar visible')[0].getElementsByTagName('input')[2].value='"+link+"';")
self.driver.execute_script("document.getElementsByClassName('media-sidebar visible')[0].getElementsByTagName('textarea')[1].value='"+link+"';")
self.driver.execute_script("document.getElementsByClassName('attachment-display-settings')[0].getElementsByTagName('input')[0].value='"+linka+"';")
time.sleep(1)
self.driver.execute_script("document.getElementsByClassName('button media-button button-primary button-large media-button-insert')[0].click();")
self.driver.execute_script("document.getElementById('publish').click();")
time.sleep(1)
I apologize in advance for ambiguity and thank you for your help
xl = pd.ExcelFile(input("C:\Praca\dane.xlsx"))and states that there is no such file.