forked from anujram178/googleScraper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwriteToExcel.py
More file actions
36 lines (29 loc) · 880 Bytes
/
Copy pathwriteToExcel.py
File metadata and controls
36 lines (29 loc) · 880 Bytes
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
import openpyxl
from pathlib import Path
import search
import sys
# setting path
# S = Search()
helper = search.Search()
xlsx_file = Path(sys.argv[1])
print(sys.argv[1])
print(xlsx_file)
# read file
wb_obj = openpyxl.load_workbook(xlsx_file)
# read active sheet from workbook
wsheet = wb_obj.active
print(wsheet.max_row, wsheet.max_column)
rowNumber = 0
for row in wsheet.iter_rows(max_row=wsheet.max_row):
rowNumber += 1
if rowNumber != 1:
nameCell = 'B' + str(rowNumber)
stateCell = 'G' + str(rowNumber)
googleQuery = wsheet[nameCell].value.lower() + ' ' + wsheet[stateCell].value.lower()
results = helper.scrapeResults(googleQuery)
urlDict = helper.findUrl(results)
webAddressCell = 'J' + str(rowNumber)
if urlDict['exists'] == True:
wsheet[webAddressCell] = urlDict['link']
print("this is the link: ", urlDict['link'])
wb_obj.save(xlsx_file)