-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (21 loc) · 854 Bytes
/
main.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
import urllib3
import xlwt
from bs4 import BeautifulSoup
word = input('Enter the word: ')
keywords = []
session = urllib3.PoolManager()
request = session.request('GET', f'https://www.google.com/search?q={word}')
content = BeautifulSoup(request.data, 'html.parser')
for i in content.find_all('div', {'class': 'BNeawe s3v9rd AP7Wnd lRVwie'}):
keywords.append(i.text)
excel = xlwt.Workbook()
sh = excel.add_sheet('my data')
for j in range(len(keywords)):
req = session.request('GET', f'https://www.google.com/search?q={keywords[j]}')
cont = BeautifulSoup(req.data, 'html.parser')
sh.write(0, j, keywords[j])
items = cont.find_all('div', {'class': 'BNeawe s3v9rd AP7Wnd lRVwie'})
for i in range(len(items)):
sh.write(i+1, j, items[i].text)
print('Success, view the keywords.xls file.')
excel.save(word + '.xls')