-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaceholder.txt
59 lines (46 loc) · 1.65 KB
/
placeholder.txt
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
58
59
from bs4 import BeautifulSoup
import requests
from urllib3.exceptions import InsecureRequestWarning
from urllib3 import disable_warnings
from fake_useragent import UserAgent
disable_warnings(InsecureRequestWarning)
from RowMethods import RowMethods
ua = str(UserAgent().random)
headers = {'User-Agent': ua}
class GetItem():
def __init__(self):
self.soup = None
def soup_generator(self, var, id, is_id=False):
if is_id:
url = f"https://www.light.gg/db/items/{id}/{var.lower().replace('%20', '-')}/"
else:
url = f"https://www.light.gg/db/search/?q={var}"
print(url)
html = requests.get(url, headers=headers, verify=False)
soup = BeautifulSoup(html.text, 'html.parser')
return soup
def get_item_by_id(self, id):
self.soup = self.soup_generator(id, is_id=True)
return self.soup
def get_item_by_name(self, name):
name = name.replace(' ', '%20')
soup = self.soup_generator(name, '', is_id=False)
rows = soup.find_all('div', class_='item-row')
row = rows[1].find_all('div')
methods = RowMethods(row)
id = methods.get_item_id()
self.soup = self.soup_generator(name, id, is_id=True)
return self.soup
def get_item(self, item):
if item.isdigit():
return self.get_item_by_id(item)
else:
return self.get_item_by_name(item)
def get_item_name(self):
return self.soup
items = GetItem()
item = items.get_item('The Last Word')
#print(item)
divs = item.find('div', class_='body-content')
#print(divs)
#print(len(sub_divs))