|
@@ -8,6 +8,7 @@ import urllib.parse
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
|
from selenium.webdriver.common.by import By
|
|
|
from selenium.webdriver.chrome.service import Service
|
|
|
+from selenium.webdriver.common.keys import Keys
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
import codecs
|
|
|
import random
|
|
@@ -53,16 +54,17 @@ def process_query(qs):
|
|
|
client=qs[2]
|
|
|
domain=qs[3]
|
|
|
global driver
|
|
|
- escaped_search_term = urllib.parse.quote(q)
|
|
|
- googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(escaped_search_term, 100, 'zh-TW')
|
|
|
- print(googleurl)
|
|
|
+ googleurl = 'https://www.google.com/?num=100'
|
|
|
driver.get(googleurl)
|
|
|
+ time.sleep(6)
|
|
|
+ send_kw_elmt = driver.find_element(By.XPATH, '/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input')
|
|
|
+ send_kw_elmt.send_keys(q)
|
|
|
+ time.sleep(3)
|
|
|
+ send_kw_elmt.send_keys(Keys.ENTER)
|
|
|
+ time.sleep(6)
|
|
|
time.sleep(10)
|
|
|
- # fname=term.replace(' ','_')
|
|
|
- # driver.save_screenshot('c:/tmp/seo/'+fname+'.png')
|
|
|
- # df=pd.DataFrame()
|
|
|
|
|
|
- elmts = driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
|
|
|
+ elmts = driver.find_elements(By.XPATH,"//div[@class='yuRUbf']/a")
|
|
|
print('網頁數量',len(elmts))
|
|
|
idx = 1
|
|
|
for elmt in elmts:
|