-
-
Save clarissarjtai/86f853944dff776e0969e316fedd2763 to your computer and use it in GitHub Desktop.
google map review
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import time | |
import pandas as pd | |
from datetime import datetime | |
from selenium import webdriver | |
from bs4 import BeautifulSoup as Soup | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.wait import WebDriverWait | |
from selenium.webdriver.common.action_chains import ActionChains | |
from selenium.webdriver.support import expected_conditions as EC | |
# 點擊查看所有評論 | |
# 原本的 class name 中存在空格:'allxGeDnJMl__button allxGeDnJMl__button-text',會讓程式抓不到 | |
# 所以空格的部分要改成「.」才能成功抓取 | |
review_click = browser.find_elements_by_class_name('allxGeDnJMl__button.allxGeDnJMl__button-text') | |
# 評論分頁下滑 | |
pane = browser.find_element_by_xpath('//*[@id="pane"]/div/div[1]/div/div/div[2]') | |
browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", pane) | |
# 點擊返回店家頁面 | |
WebDriverWait(browser, 15).until(EC.presence_of_element_located((By.CLASS_NAME, 'geoUxComponentsAppbarButtonWrapper'))) | |
BacktoStore_btn = browser.find_elements_by_class_name('geoUxComponentsAppbarButtonWrapper')[0] | |
BacktoStore_btn.click() | |
# 點擊返回搜尋結果 | |
WebDriverWait(browser, 30).until(EC.presence_of_element_located((By.CLASS_NAME, 'section-back-to-list-button.blue-link.noprint'))) | |
back_btn = browser.find_elements_by_class_name('section-back-to-list-button.blue-link.noprint')[0] | |
back_btn.click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment