|
@@ -98,6 +98,7 @@ def scrolling(driver, pgnum):
|
|
|
|
|
|
def run_once(jsobj):
|
|
|
table = db['google_rank']
|
|
|
+ date = jsobj['date']
|
|
|
print(jsobj)
|
|
|
global driver
|
|
|
|
|
@@ -111,12 +112,12 @@ def run_once(jsobj):
|
|
|
kw = jsobj['kw']
|
|
|
fname = jsobj['fname']
|
|
|
|
|
|
- if jsobj.get('domain') is None:
|
|
|
- exclude = jsobj['exclude']
|
|
|
- domain = None
|
|
|
- else:
|
|
|
- domain = jsobj['domain']
|
|
|
- exclude = None
|
|
|
+ # if jsobj.get('domain') is None:
|
|
|
+ # exclude = jsobj['exclude']
|
|
|
+ # domain = None
|
|
|
+ # else:
|
|
|
+ # domain = jsobj['domain']
|
|
|
+ # exclude = None
|
|
|
city_map = {'chicago': ['42.04866173771369', '-87.68260072643513'],
|
|
|
'miami': ['25.764458843530548', '-80.19787522585152'],
|
|
|
'wc': ['38.96071674051165', '-77.03155367248387'],
|
|
@@ -145,7 +146,7 @@ def run_once(jsobj):
|
|
|
elmts = driver.find_elements(By.XPATH, "//div[@class='yuRUbf']/a")
|
|
|
numresults = len(elmts)
|
|
|
print('搜尋結果數量', numresults)
|
|
|
- # driver.save_screenshot('C:\/Users\/s1301\/Pictures\/Saved Pictures\/' + fname + ".png")
|
|
|
+ driver.save_screenshot('C:\/Users\/s1301\/Pictures\/Saved Pictures\/' +date +fname + ".png")
|
|
|
if numresults == 0:
|
|
|
send_msg('stop working...')
|
|
|
sys.exit()
|
|
@@ -174,42 +175,42 @@ def run_once(jsobj):
|
|
|
datadict['結果名次'].append(str(idx))
|
|
|
datadict['結果說明'].append(desc)
|
|
|
|
|
|
- if len(txt) > 10:
|
|
|
- if domain is not None:
|
|
|
- for d in domain:
|
|
|
- if d in href:
|
|
|
- print('found....')
|
|
|
- print('clicked....')
|
|
|
- print(href)
|
|
|
- print(txt)
|
|
|
- print("ranking", idx)
|
|
|
- found = True
|
|
|
- return
|
|
|
- else:
|
|
|
- ex = False
|
|
|
- for ee in exclude:
|
|
|
- if ee in href:
|
|
|
- ex = True
|
|
|
- if not ex:
|
|
|
- test_lst.append(elmt)
|
|
|
- txt_dict[elmt] = txt
|
|
|
+ # if len(txt) > 10:
|
|
|
+ # if domain is not None:
|
|
|
+ # for d in domain:
|
|
|
+ # if d in href:
|
|
|
+ # print('found....')
|
|
|
+ # print('clicked....')
|
|
|
+ # print(href)
|
|
|
+ # print(txt)
|
|
|
+ # print("ranking", idx)
|
|
|
+ # found = True
|
|
|
+ # return
|
|
|
+ # else:
|
|
|
+ # ex = False
|
|
|
+ # for ee in exclude:
|
|
|
+ # if ee in href:
|
|
|
+ # ex = True
|
|
|
+ # if not ex:
|
|
|
+ # test_lst.append(elmt)
|
|
|
+ # txt_dict[elmt] = txt
|
|
|
|
|
|
idx += 1
|
|
|
|
|
|
- if exclude is not None:
|
|
|
- print('exclude')
|
|
|
- elmt = random.choice(test_lst[5:])
|
|
|
- print(elmt)
|
|
|
- print(txt_dict[elmt])
|
|
|
-
|
|
|
- webdriver.ActionChains(driver).move_to_element(elmt).perform()
|
|
|
- # elmt.click()
|
|
|
- webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
|
|
|
- time.sleep(5)
|
|
|
-
|
|
|
- if not found:
|
|
|
- table.insert(
|
|
|
- {'ranking': -1, 'kw': kw, 'results': numresults, 'url': '', 'title': '未收錄', 'descrption': desc})
|
|
|
+ # if exclude is not None:
|
|
|
+ # print('exclude')
|
|
|
+ # elmt = random.choice(test_lst[5:])
|
|
|
+ # print(elmt)
|
|
|
+ # print(txt_dict[elmt])
|
|
|
+ #
|
|
|
+ # webdriver.ActionChains(driver).move_to_element(elmt).perform()
|
|
|
+ # # elmt.click()
|
|
|
+ # webdriver.ActionChains(driver).move_to_element(elmt).click().perform()
|
|
|
+ # time.sleep(5)
|
|
|
+ #
|
|
|
+ # if not found:
|
|
|
+ # table.insert(
|
|
|
+ # {'ranking': -1, 'kw': kw, 'results': numresults, 'url': '', 'title': '未收錄', 'descrption': desc})
|
|
|
|
|
|
df['搜尋詞'] = datadict['搜尋詞']
|
|
|
df['結果標題'] = datadict['結果標題']
|
|
@@ -217,7 +218,7 @@ def run_once(jsobj):
|
|
|
df['結果名次'] = datadict['結果名次']
|
|
|
df['結果說明'] = datadict['結果說明']
|
|
|
|
|
|
- # df.to_excel('C:\/Users\/s1301\/Pictures\/Saved Pictures\/'+fname+".xls")
|
|
|
+ df.to_excel('C:\/Users\/s1301\/Pictures\/Saved Pictures\/'+date+fname+".xls")
|
|
|
|
|
|
|
|
|
|
|
@@ -232,11 +233,4 @@ def run_once(jsobj):
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
-class JParams(object):
|
|
|
-
|
|
|
- def get(self, jsobj):
|
|
|
- run_once(jsobj)
|
|
|
-
|
|
|
-
|
|
|
-if __name__ == '__main__':
|
|
|
- fire.Fire(JParams)
|
|
|
+run_once({'kw':'angelo koo','fname':'miami','date':'1208'})
|