-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
57 lines (44 loc) · 2.29 KB
/
Copy pathparser.py
File metadata and controls
57 lines (44 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import time
import logging
from bs4 import BeautifulSoup
from selenium import webdriver
logger = logging.getLogger(__name__)
def _get_coin(coin_name, coin_id, coin_votes) -> dict:
"""Returns coin in json format"""
return {'name': coin_name.text.strip(),
'id': coin_id['href'].replace('/coin/', '').strip(),
'votes': coin_votes.text.strip()
}
def _todays_best(parser: BeautifulSoup) -> dict:
"""Parser that parse today's best catalog on https://coinhunt.cc"""
coins_table = parser.find('div', class_='Landing_table__2kfJT')
coins = coins_table.find_all('div', class_='sc-gKAaRy dkOltH') + \
coins_table.find_all('div', class_='sc-hKFxyN jtSqOG') + \
coins_table.find_all('div', class_='sc-jSFjdj bcukKH') + \
coins_table.find_all('div', class_='sc-dlnjwi keogPe')
if not coins:
logger.critical(f'coins is the {coins}')
for coin in coins:
coin_name = coin.find('div',
class_='px-0 align-self-center Landing_ColFontSize__1Ma9T Landing_FullName__3ORsT col') \
or coin.find('div',
class_='px-0 align-self-center Landing_ColFontSize__1Ma9T Landing_FullName__3ORsT Landing_fourthPlaceName__3ukzi col') \
or coin.find('div',
class_='px-0 align-self-center Landing_ColFontSize__1Ma9T col-2')
coin_id = coin.find('a', class_='Landing_RowLink__1d-wr', href=True)
coin_votes = coin.find('div', class_='Landing_VoteText__wuky1')
if coin_votes:
yield _get_coin(coin_name, coin_id, coin_votes)
def get_coins_in_json() -> list[dict]:
"""Initializes a parser and returns today's best catalog"""
options = webdriver.FirefoxOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Firefox(executable_path='/Users/arsen/Desktop/geckodriver', options=options)
driver.get('https://coinhunt.cc')
element = driver.find_element_by_css_selector('p.Landing_ShowAll__1jQ77')
driver.execute_script('arguments[0].click();', element)
time.sleep(1)
soup = BeautifulSoup(driver.page_source, 'html.parser')
return list(_todays_best(soup))