-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebparse.py
61 lines (39 loc) · 1.18 KB
/
webparse.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from googlesearch import search
from bs4 import BeautifulSoup
import requests
from nltk.corpus import stopwords
from nltk.tokenize import RegexpTokenizer
from nltk.corpus import stopwords
from nltk.stem import PorterStemmer
from nltk.stem.wordnet import WordNetLemmatizer
# gives a list
def flist(link):
tk = RegexpTokenizer(r'\w+')
url = link
sw=stopwords.words('english')
ps = PorterStemmer()
info = requests.get(url)
textlist = ''
soup = BeautifulSoup(info.text, "html5lib")
for script in soup(["script", "style"]):
script.extract()
textlist = tk.tokenize(soup.get_text())
wordlist=[]
for x in textlist:
if x not in sw:
wordlist.append(x)
for x in range(len(wordlist)):
wordlist[x]=ps.stem(wordlist[x])
return wordlist
# query = input()
def giveQueryandgetString(query):
searched_links=search(query, tld="co.in", num=5,stop = 4,pause=2)
resultString = ''
for i in searched_links:
# print(i)
links_wordlist=flist(i)
for x in links_wordlist:
x+=' '
resultString+= x
return resultString
# print(giveQueryandgetString('suhas gumma'))