I can not figure out how to create a folder with the date today, and save screenshots there. And the next day, create another folder with tomorrow's date and write other files there, etc.
date_today = str (datetime.datetime.today (). strftime ("% d_% m_% Y_% H_% M")) name_file = str (n) + ' ' + ('sait ') + str (link_now) + str (date_today)
driver.save_screenshotg ('\' + date_today + '\' + name_file)
from selenium import webdriver from selenium.webdriver.common.keys import Keys import time,random,re,datetime,os,errno import traceback;#uotput error from selenium.webdriver.common.action_chains import ActionChains saity=['http://lenta.ru/rss/news','http://www.kommersant.ru/RSS/main.xml','http://www.kommersant.ru/RSS/news.xml','http://rssportal.ru/feed/173256.xml','http://www.levada.ru/rss.xml','http://wsrss.bbc.co.uk/russian/index.xml','http://inosmi.ru/misc/export/xml/rss/translation.xml','http://news.google.ru/news?ned=ru_ru&topic=t&output=atom','http://112.ua/rss','http://thebestvideo.net/feed','http://feeds.feedburner.com/Astrobene'] driver = webdriver.Chrome() driver.maximize_window() wait_1=9 n=0 for i in reversed(range(len(saity))): try: link_now = saity.pop(random.randint(0, i)) driver.get(link_now) time.sleep(wait_1) print(link_now) date_today= str(datetime.datetime.today().strftime("%d_%m_%Y_%H_%M")) name_file=str(n)+'_'+('sait_')+str(link_now)+str(date_today) name_file= name_file.replace('http://','').replace('.','').replace('/','_') name_file= name_file+'.png' #было бы замечательно в jpg print(name_file) driver.save_screenshot('\\'+date_today+'\\'+name_file) n+=1 except Exception as exc: print(exc) traceback.print_exc()
saity, and the data you take fromgeneratory. The variablennot defined. As for saving a file, it would not be bad to first create a folder into which you saved to assemble (for example,os.mkdir). Concerning jpg - allselenium.info/… - strawdogstrftimeand so returns a string, so you do not need to call str for it 2) instead ofname_file=str(n)+'_'+('sait_')+str(link_now)+str(date_today)write through''.formatorf-строки, the code will be easier, the world is kinder, etc. :) 3) when in thedriver.save_screenshottransfer the path with a new folder, does it create a folder and save a screenshot there or swear on the path? - gil9red