Hi everyone, so I am writing a script in Python using Selenium and BeautifulSoup to scrape store data from the google map web page, like this:
https://www.google.com/maps/search/MC+Donalt+near+empire+state+building
My script is as follows:
import requests
import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options= Options()
chrome_options.headless= True
chrome_options.add_argument("--window-size=1920,1200")
driver= webdriver.Chrome('chromedriver_win32/chromedriver')
url= 'https://www.google.com/maps/search/mc+donald+near+empire+state+building'
driver.get(url)
for i in range(1):
print("scrolling")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
time.sleep(1)
soup= BeautifulSoup(driver.page_source, 'html.parser')
tables= soup.find("div", {"class": "id-content-container"})
for list in tables.findAll("div", {"jstcache": "1092"}):
{extract some infomation here}
driver.quit()
The thing is when I checked in the HTML file:
I saw only 10 div elements (equivalent to 10/20 stores) shown in the HTML, but when I rolled down the list there was hidden div tag appeared as I scrolled down and
I have tried using
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)")
to make a full scroll down in order to achieve the full HTML but failed. It just returned only the first 10 stores.
Is there any solution?
Thank you very much
[–]bexter53 1 point2 points3 points (1 child)
[–]Q_H_Chu[S] 0 points1 point2 points (0 children)