|
@@ -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
|
|
@@ -51,16 +52,20 @@ def process_query(qs):
|
|
|
q=qs[0]
|
|
|
domain=qs[1]
|
|
|
global driver
|
|
|
- googleurl = 'https://www.google.com/search?q={}&num={}&hl={}'.format(urllib.parse.quote(q), 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)
|
|
|
|
|
|
elmts=driver.find_elements_by_xpath("//div[@class='yuRUbf']/a")
|
|
|
|
|
|
idx=1
|
|
|
ranking=-1
|
|
|
- print(len(elmts))
|
|
|
+ print('網頁數量',len(elmts))
|
|
|
# driver.save_screenshot('c:/tmp/test.png')
|
|
|
if 'site' in q:
|
|
|
href = elmts[0].get_attribute('href')
|