|
@@ -42,55 +42,55 @@ def rua():
|
|
|
|
|
|
def process_one(item):
|
|
|
global driver
|
|
|
- for i in item:
|
|
|
- term = i[0]
|
|
|
- domain = i[1]
|
|
|
- print(term,domain)
|
|
|
|
|
|
- escaped_search_term = urllib.parse.quote(term)
|
|
|
- googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(escaped_search_term, 100, 'zh-TW')
|
|
|
- print(googleurl)
|
|
|
- driver.get(googleurl)
|
|
|
- time.sleep(6)
|
|
|
- # fname=term.replace(' ','_')
|
|
|
- # driver.save_screenshot('c:/tmp/seo/'+fname+'.png')
|
|
|
- # df=pd.DataFrame()
|
|
|
-
|
|
|
- elmts = driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
|
|
|
- cnt = 1
|
|
|
- datadict = {'搜尋詞': [], '結果標題': [], '結果網址': [], '結果名次': []}
|
|
|
-
|
|
|
- for elmt in elmts:
|
|
|
- try:
|
|
|
- href = elmt.get_attribute('href')
|
|
|
+ term = item[0]
|
|
|
+ domain = item[1]
|
|
|
+ print(term,domain)
|
|
|
|
|
|
- datadict['搜尋詞'].append(term)
|
|
|
- datadict['結果標題'].append(elmt.text)
|
|
|
- datadict['結果網址'].append(href)
|
|
|
- datadict['結果名次'].append(str(cnt))
|
|
|
- if domain in href:
|
|
|
- print(href)
|
|
|
- print(elmt.text)
|
|
|
- table.insert(
|
|
|
- {'title': elmt.text, 'url': href, 'keyword': term, 'dt': datetime.datetime.now(), 'num': cnt})
|
|
|
- cnt += 1
|
|
|
- except:
|
|
|
- print('href2 exception')
|
|
|
- traceback.print_exc()
|
|
|
- if len(datadict['結果標題']) <= 0:
|
|
|
- print('None')
|
|
|
- driver.quit()
|
|
|
- sys.exit()
|
|
|
- # df['搜尋詞']=datadict['搜尋詞']
|
|
|
- # df['結果標題']=datadict['結果標題']
|
|
|
- # df['結果網址']=datadict['結果網址']
|
|
|
- # df['結果名次']=datadict['結果名次']
|
|
|
- #
|
|
|
- # df.to_excel('/Users/zooeytsai/'+fname+".xls")
|
|
|
-
|
|
|
+ escaped_search_term = urllib.parse.quote(term)
|
|
|
+ googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(escaped_search_term, 100, 'zh-TW')
|
|
|
+ print(googleurl)
|
|
|
+ driver.get(googleurl)
|
|
|
+ time.sleep(6)
|
|
|
+ # fname=term.replace(' ','_')
|
|
|
+ # driver.save_screenshot('c:/tmp/seo/'+fname+'.png')
|
|
|
+ # df=pd.DataFrame()
|
|
|
+
|
|
|
+ elmts = driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
|
|
|
+ cnt = 1
|
|
|
+ datadict = {'搜尋詞': [], '結果標題': [], '結果網址': [], '結果名次': []}
|
|
|
+
|
|
|
+ for elmt in elmts:
|
|
|
+ try:
|
|
|
+ href = elmt.get_attribute('href')
|
|
|
+
|
|
|
+ datadict['搜尋詞'].append(term)
|
|
|
+ datadict['結果標題'].append(elmt.text)
|
|
|
+ datadict['結果網址'].append(href)
|
|
|
+ datadict['結果名次'].append(str(cnt))
|
|
|
+ if domain in href:
|
|
|
+ print(href)
|
|
|
+ print(elmt.text)
|
|
|
+ table.insert(
|
|
|
+ {'title': elmt.text, 'url': href, 'keyword': term, 'dt': datetime.datetime.now(), 'num': cnt})
|
|
|
+ cnt += 1
|
|
|
+ except:
|
|
|
+ print('href2 exception')
|
|
|
+ traceback.print_exc()
|
|
|
+ if len(datadict['結果標題']) <= 0:
|
|
|
+ print('None')
|
|
|
driver.quit()
|
|
|
- print('中場休息')
|
|
|
- time.sleep(randint(90, 120))
|
|
|
+ sys.exit()
|
|
|
+ # df['搜尋詞']=datadict['搜尋詞']
|
|
|
+ # df['結果標題']=datadict['結果標題']
|
|
|
+ # df['結果網址']=datadict['結果網址']
|
|
|
+ # df['結果名次']=datadict['結果名次']
|
|
|
+ #
|
|
|
+ # df.to_excel('/Users/zooeytsai/'+fname+".xls")
|
|
|
+
|
|
|
+ driver.quit()
|
|
|
+ print('中場休息')
|
|
|
+ time.sleep(randint(90, 120))
|
|
|
|
|
|
|
|
|
def run_once(pport,item):
|
|
@@ -118,11 +118,10 @@ def run_once(pport,item):
|
|
|
cursor = db.query('select term,domain from seo.selected_kw')
|
|
|
for c in cursor:
|
|
|
lst.append([c['term'],c['domain']])
|
|
|
-for i in lst:
|
|
|
- term = i[0]
|
|
|
- domain = i[1]
|
|
|
+
|
|
|
|
|
|
for i in lst:
|
|
|
+ print(i)
|
|
|
while True:
|
|
|
try:
|
|
|
os.system('docker container restart tiny9')
|