52 lines
1.3 KiB
Python
Executable file
52 lines
1.3 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
PAGE_URL = "https://technical.city/ru/cpu/best-price-to-performance"
|
|
|
|
SORT_FIELD_PRICE = "price"
|
|
SORT_FIELD_QUALITY = "performance"
|
|
|
|
SORT_ORDER_DES = "down"
|
|
SORT_ORDER_ASC = "up"
|
|
|
|
USD_PRICE = 81.37
|
|
|
|
def request_page(page_num=1, sort_field=SORT_FIELD_PRICE, sort_order=SORT_ORDER_ASC):
|
|
resp = requests.get(PAGE_URL, params={
|
|
"pg": page_num,
|
|
"sort_field": sort_field,
|
|
"sort_order": sort_order
|
|
})
|
|
|
|
page = BeautifulSoup(resp.text, features="lxml")
|
|
|
|
for i in page.find_all("tr"):
|
|
tds = [ x.text.strip() for x in i.find_all("td") ]
|
|
|
|
if len(tds) < 7:
|
|
continue
|
|
|
|
name = tds[1]
|
|
price = float(tds[4].replace("USD", "").strip()) * USD_PRICE
|
|
quality = float(tds[5])
|
|
cores = tds[6].split("/")[0].strip()
|
|
threads = tds[6].split("/")[1].strip()
|
|
|
|
manufacturer = i.find("img", {"class": "item_photo"})["alt"].split()[0]
|
|
|
|
yield [ manufacturer, name, price, quality, cores, threads ]
|
|
|
|
cpus = []
|
|
|
|
for i in range(1, 50):
|
|
print("Fetching page", i, "...", end="\r")
|
|
cpus += list(request_page(i))
|
|
|
|
print("fetched all ", end="\r")
|
|
|
|
cpus.sort(key=lambda x: x[2] / x[3])
|
|
|
|
for i in cpus:
|
|
print(*i)
|