-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_page.py
41 lines (33 loc) · 1.56 KB
/
load_page.py
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
import requests
from bs4 import BeautifulSoup
class Load_page:
def __init__(self,query):
self.response = requests.get('https://www.entireweb.com/web?q='+query)
def get_soup(self,parser='lxml'):
content = self.response.content
self.soup = BeautifulSoup(content,parser)
advertisements = self.soup.find_all('div',{'class':'web-results lastad'})
for i in advertisements:
i.decompose()
return self.soup
def get_spell_title(self):
if self.soup.find('div',{'class':'web-results','class':'query-spell'}) == None:return False
self.spell_title = self.soup.find('div',{'class':'web-results','class':'query-spell','class':'spell-title'}).text
try: self.spell_title = self.spell_title.replace('\n','')
except:pass
return self.spell_title.strip()
def get_spell_description(self):
if self.soup.find('div',{'class':'web-results','class':'query-spell'}) == None:return False
self.spell_description = self.soup.find('div',{'class':'web-results','class':'query-spell','class':'spell-description'}).text
try: self.spell_description = self.spell_description.replace('\n','')
except: pass
return self.spell_description.strip()
# for testing purpose
if __name__=="__main__":
page = Load_page(input('Query'))
print("This is for debugging purposes")
print('Run search.py or entity.py or results.py')
#print(page.get_soup().prettify())
page.get_soup()
print(page.get_spell_title())
print(page.get_spell_description())