init commit
This commit is contained in:
commit
e53083482d
2 changed files with 65 additions and 0 deletions
13
LICENSE
Normal file
13
LICENSE
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
52
main.py
Executable file
52
main.py
Executable file
|
@ -0,0 +1,52 @@
|
||||||
|
#!/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)
|
Loading…
Add table
Add a link
Reference in a new issue