Парсю процессоры с этого сайта (вернее с одной страницы)
https://www.citilink.ru/product/processor-amd-ryze... вот код
from bs4 import BeautifulSoup
import requests
def get_start(url):
headers ={
"accept" : "application/json",
"accept-encoding" : "gzip, deflate, br",
"accept-language": "ru,en-US;q=0.9,en;q=0.8,ru-RU;q=0.7",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
}
r = requests.get(url=url, headers= headers)
with open("citilink2.html", "w") as file:
file.write(r.text)
r = requests.get(url=url, headers= headers)
soup = BeautifulSoup(r.text, "lxml")
with open("citilink2.html") as file:
src = file.read()
cpu_link = soup.find_all("div", class_="ProductCardHorizontal__header-block")
cpu_urls =[]
for cpu_cards in cpu_link:
cpu_cards = cpu_cards.find("a")
cpu_cards = "https://www.citilink.ru" + cpu_cards.get("href")
cpu_urls.append(cpu_cards)
#print(cpu_cards)
#print(len(cpu_cards)) # check how many posichion we have
#print(cpu_urls)
for cpu_cards in cpu_urls[0:1]:
r = requests.get(cpu_cards, headers)
cpu_name = cpu_cards.split("/")[-2]
# with open(f'all_citilink_pages/{cpu_name}', 'w') as file:
# file.write(r.text)
with open(f'all_citilink_pages/{cpu_name}') as file:
src = file.read()
soup=BeautifulSoup(src, "lxml")
#find_names = soup.find("div", class_="Container")
# project_logo = soup.find("img", class_="__image-upper PreviewList__image Image").get("src") КАК МОЖНО НАЙТИ КАРТИНКУ
# print(project_logo)
find_cpu_name = soup.find("div", class_="ProductCardLayout__product-description").find("h1").text
print(find_cpu_name)
find_price = soup.find("div",class_="ProductPrice ProductPrice_default ProductHeader__price-default").find("span", class_="ProductHeader__price-default_current-price").text
print("Новая цена: " + find_price)
try:
find_over_price = soup.find("div", class_="ProductHeader__price-block").find("span", class_="ProductHeader__price-old_current-price").text
print("Старая цена: " + find_over_price)
except Exception:
find_over_price = "Скидочки нету"
try:
find_stars = soup.find("div", class_="ProductHeader__info-item").find("span", class_="IconWithCount__count").text
print("Средняя оценка: " + find_stars)
except Exception:
find_stars = "Оценки нету"
def main():
get_start("https://www.citilink.ru/catalog/processory/?pf=discount.any%2Crating.any%2Cms_action&f=discount.any%2Crating.any%2Cms_action&price_min=1990&price_max=20000")
if __name__ == "__main__":
main()
выводится
Процессор AMD Ryzen 5 3600, SocketAM4, OEM [100-000000031]
Новая цена:
15 290
Старая цена:
16 590
Средняя оценка:
4.8
должно выводиться все ровно,как сделать это? заранее спасибо
здесь не видно, но название процессора тоже с пробелами