import requests
from bs4 import BeautifulSoup
from lxml import html
import csv
url = 'https://www.yoox.com/ru/%D0%B4%D0%BB%D1%8F%20%D0%BC%D1%83%D0%B6%D1%87%D0%B8%D0%BD/%D0%BE%D0%B4%D0%B5%D0%B6%D0%B4%D0%B0/shoponline#/dept=clothingmen&gender=U&page=1&season=X'
headers = {'user-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
}
def getClothes(url,page_id):
clothes = []
respones = requests.get(url,headers=headers)
soup = BeautifulSoup(respones.text,'lxml')
mainContent = soup.find('div',id=f'srpage{page_id}')
products = mainContent.find_all('div',class_='col-8-24')
for product in products:
brand = product.find('div',class_='itemContainer')['data-brand'] # Бренд
cod10 = product.find('div',class_='itemContainer')['data-current-cod10'] # Для формирования ссылки yoox.com/ru/{cod10}/item
category = product.find('div',class_='itemContainer')['data-category'] # Категория
oldPrice = product.find('span',class_='oldprice text-linethrough text-light') # Старая цена (может не быть)
newPrice = product.find('span',class_='newprice font-bold') # Новая цена (может не быть)
if oldPrice is not None:
# Данный код выполняется только, если на товар есть скидка
sizes = product.find_all('div',class_='size text-light')
str_sizes = ''
for x in sizes:
str_sizes += x.text.strip().replace('\n',';')
clothes.append({'art':cod10,
'brand':brand,
'category':category,
'url':f'https://yoox.com/ru/{cod10}/item',
'oldPrice':oldPrice.text,
'newPrice':newPrice.text,
'sizes':str_sizes
})
return clothes
def getLastPage(url):
respones = requests.get(url,headers=headers)
soup = BeautifulSoup(respones.text,'lxml')
id = soup.find_all('li', class_ = 'text-light')[2]
return int(id.a['data-total-page']) + 1
def writeCsvHeader():
with open('yoox_man_clothes.csv', 'a', newline='') as file:
a_pen = csv.writer(file)
a_pen.writerow(('Артикул', 'Ссылка', 'Размеры', 'Бренд', 'Категория', 'Старая цена', 'Новая цена'))
def files_writer(clothes):
with open('yoox_man_clothes.csv', 'a', newline='') as file:
a_pen = csv.writer(file)
for clothe in clothes:
a_pen.writerow((clothe['art'], clothe['url'], clothe['sizes'], clothe['brand'], clothe['category'], clothe['oldPrice'], clothe['newPrice']))
if __name__ == '__main__':
writeCsvHeader() # Запись заголовка в csv файл
lastPage = getLastPage(url) # Получаем последнею страницу
for x in range(1,lastPage): # Вместо 1 и lastPage можно указать диапазон страниц. Не начинайте парсить с нулевой страницы!
print(f'Скачавается: {x} из {lastPage-1}')
url = f'https://www.yoox.com/RU/shoponline?dept=clothingmen&gender=U&page={x}&season=X&clientabt=SmsMultiChannel_ON%2CSrRecommendations_ON%2CNewDelivery_ON%2CRecentlyViewed_ON%2CmyooxNew_ON'
files_writer(getClothes(url,x)) # Парсим и одновременно заносим данные в csv
import requests
from bs4 import BeautifulSoup
url = 'https://qna.habr.com/search?q='
def search(keyword):
responce = requests.get(url+keyword)
soup = BeautifulSoup(responce.text,"html.parser")
try:
contents = soup.find_all('li',class_='content-list__item')
for answers in contents:
title = answers.find('a',class_='question__title-link question__title-link_list').text.strip()
count = answers.find('div',class_='mini-counter__count mini-counter__count_grey').text.strip()
print(f'{title} {count}')
except:
pass
keyword = input('Введите запрос: ')
search(keyword)
from datetime import datetime
firstDate = '16022020'
secondDate = '01012020'
f_date = datetime.strptime(firstDate,'%d%m%Y').date()
s_date = datetime.strptime(secondDate,'%d%m%Y').date()
print((f_date-s_date).days)
from datetime import datetime,timedelta,date
firstDate = '16022020'
secondDate = '01012020'
f_date = datetime.strptime(firstDate,'%d%m%Y').date()
s_date = datetime.strptime(secondDate,'%d%m%Y').date()
delta = timedelta(days=1)
while s_date <= f_date:
print (s_date.strftime("%d.%m.%Y"))
s_date += delta
import telebot
import pyowm
owm = pyowm.OWM('key', language = "ru")
bot = telebot.TeleBot('token')
@bot.message_handler(content_types=['text'])
def send_echo(message):
try:
observation = owm.weather_at_place( message.text )
w = observation.get_weather()
temp = w.get_temperature('celsius')["temp"]
hum = w.get_humidity()
time = w.get_reference_time(timeformat='iso')
wind = w.get_wind()["speed"]
answer ="В городе " + message.text + " сейчас " + w.get_detailed_status() + "\n"
answer += "Температура сейчас в районе " + str(temp) + "\n\n" + "\nСкорость ветра: " + str(wind) + "м/с" + "\n" + "\nВлажность: " + str(hum) + "%" + "\n" + "\nВремя: " + str(time) + "\n"
if temp < 11:
answer += "Сейчас очень холодно."
elif temp < 20:
answer += "Сейчас прохладно, лучше одеться потеплее."
else:
answer += "Температура в норме!"
bot.send_message(message.chat.id, answer)
except:
bot.send_message(message.chat.id,'Ошибка! Город не найден.')
bot.polling( none_stop = True)
input()
engine = pyttsx3.init('dummy')
command = '!скажи текст'
print(command[7:])
#текст
command2 = '!скажи много текста'
print(command2[7:])
#много текста
command = '!скажи текст'
print(command.split(' ')[1])
#текст
command = '!скажи текст'
print(command.replace('!скажи ',''))
#текст
command = '!скажи текст'
print((command[::-1][0:len(command[::-1])-7])[::-1])
#текст
import base64
command = '!скажи текст'
t = 'KGNvbW1hbmRbOjotMV1bMDpsZW4oY29tbWFuZFs6Oi0xXSktN10pWzo6LTFd'
print(eval(compile(base64.b64decode(t),'<string>', 'eval')))
#текст
import requests
from bs4 import BeautifulSoup
url = 'https://coinmarketcap.com/'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
all = soup.find_all('',class_='cmc-table-row')
for x in all:
rank = x.find('td',class_='cmc-table__cell--sort-by__rank').text
name = x.find('td',class_='cmc-table__cell--sort-by__name').text
market_cap = x.find('td',class_='cmc-table__cell--sort-by__market-cap').text
price = x.find('td',class_='cmc-table__cell--sort-by__price').text
volume = x.find('td',class_='cmc-table__cell--sort-by__volume-24-h').text
circulating_supply = x.find('td',class_='cmc-table__cell--sort-by__circulating-supply').text
change = x.find('td',class_='cmc-table__cell--sort-by__percent-change-24-h').text
print(f'{rank} {name} {market_cap} {price} {volume} {circulating_supply} {change}')
import requests
from bs4 import BeautifulSoup
url = 'https://coinmarketcap.com/'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
all = soup.find_all('',class_='cmc-table-row')
for x in all:
rank = x.find('td',class_='rc-table-cell table-col-rank rc-table-cell-fix-left').text
name = x.find('a',class_='cmc-link').find('p').text
market_cap = x.find('td',class_='rc-table-cell font_weight_500___2Lmmi').text
price = x.find('td',class_='rc-table-cell font_weight_500___2Lmmi').text
volume = x.find('div',class_='Box-sc-16r8icm-0 sc-1anvaoh-0 gxonsA').a.p.text
circulating_supply = x.find('p',class_='Text-sc-1eb5slv-0 kqPMfR').text
# change = x.find('td',class_='cmc-table__cell--sort-by__percent-change-24-h').text
print(f'{rank} {name} {market_cap} {price} {volume} {circulating_supply}')
name = input(" Ваше имя; ")
a = int(input(" Ваш возраст; ") )
print(" Ваше имя: " + name + "; и ваш возраст: " + str(a) )
what = input(" Хотите увиличить свой возраст ? (Да, Нет); ")
if what == "Да":
while True:
b = int(input(" Сколько лет хотите прибавить? ;") )
a = a + b
print(" Ваш новый возраст: " + str(a))
what = input(" Хотите увиличить свой возраст ещё раз ? (Да, Нет);")
if what == "Нет":
break
elif what == "Нет":
print(" Ну, как хочешь, пока!")
else:
print(" Я не знаю что делать :(")