from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
url = 'https://www.avito.ru/sankt-peterburg/noutbuki?cd=1'
options = Options()
options.page_load_strategy = 'eager'
driver = webdriver.Firefox(options=options)
driver.get(url)
count_pages_old = int(driver.find_elements(By.CLASS_NAME, 'pagination-item-JJq_j')[-2].text)
driver.get(f'{url}&p={count_pages_old}')
count_pages = int(driver.find_elements(By.CLASS_NAME, 'pagination-item-JJq_j')[-2].text)
original_window = driver.current_window_handle
print(f'Создаем {count_pages} вкладок')
for num_page in range(1, count_pages + 2):
driver.switch_to.new_window('tab')
page = 1
for window_handle in driver.window_handles:
driver.switch_to.window(window_handle)
print(f'Открываем страницу {page}')
driver.get(f"{url}&p={page}")
page += 1
import os
from send2trash import send2trash
array = []
for index in range(len(os.listdir())):
array.append(os.listdir()[index])
else:
count = 1
print('\nЧто удаляем? Назад - "0"')
for index in range(len(array)):
print(f'\t{count}. {array[index]}')
count += 1
what_to_delete = int(input())
def successful_delete():
print(f'\nРубрика {array[what_to_delete - 1]} успешно удалена!')
send2trash(array[what_to_delete - 1])
are_you_sure = input(f'''\nВы уверены что хотите удалить файл "{array[what_to_delete - 1]}"?
000. Да
1. Нет\n''')
if are_you_sure == '000':
successful_delete()
import os
import rename
import days
import web
def main():
while True:
os.system('cls')
print('''\nЧто Вы хотите сделать?
1. Переименовать
2. Показать дни недели
3. Получить скриншот''')
while True:
answer_main = input()
if answer_main.isnumeric():
answer_main = int(answer_main)
break
else:
print('\nПовторите попытку! Введите цифру!')
if answer_main == 1:
rename.func_rename()
if answer_main == 2:
days.func_days()
elif answer_main == 3:
web.func_web()
else:
main()
if __name__ == '__main__':
main()
import os
def func_rename():
folder = r'E:\demos\files\reports\\'
count = 1
# count increase by 1 in each iteration
# iterate all files from a directory
for file_name in os.listdir(folder):
# Construct old file name
source = folder + file_name
# Adding the count to the new file name and extension
destination = folder + "sales_" + str(count) + ".txt"
# Renaming the file
os.rename(source, destination)
count += 1
print('All Files Renamed')
print('New Names are')
# verify the result
res = os.listdir(folder)
print(res)
def func_days():
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
for day in days:
print (day)
from selenium import webdriver
import datetime
def func_web():
opt=webdriver.ChromeOptions()
opt.add_argument("--start-maximized")
driver= webdriver.Chrome(executable_path="F:\Python\work\chromedriver.exe",options=opt)
driver.get("http://xfas.in/")
# put below lines in loop
timestamp = datetime.datetime.now().strftime('%d_%m_%Y_%H_%M_%S')
driver.get_screenshot_as_file(timestamp+'.png')
print('ok')
import requests as r
from bs4 import BeautifulSoup as bs
from datetime import *
channel = 'https://t.me/s/testchannel5'
page = r.get(channel)
soup = bs(page.content, 'html.parser')
date_post = soup.find_all('span', class_='tgme_widget_message_meta')[-1].text # -1 – индекс поста
long_time = datetime.strptime(date_post, '%H:%M') + timedelta(hours=3)
correct_time = long_time.strftime('%H:%M')
print(correct_time)
import requests as r
from bs4 import BeautifulSoup as bs
from datetime import *
channel = 'https://t.me/s/testchannel5'
page = r.get(channel)
soup = bs(page.content, 'html.parser')
date_post = soup.find_all('span', class_='tgme_widget_message_meta')[-1].text # -1 – индекс поста
long_time = datetime.strptime(date_post, '%H:%M') + timedelta(hours=3)
correct_time = long_time.strftime('%H:%M')
print(correct_time)