دنبال کننده ها

۱۳۹۶ دی ۱۲, سه‌شنبه

selenium - Scrapping the data from website under the map by using python Selinium

[ad_1]



I got a requirement to pull all the URLs from a webpage and data from the map if there is a map in the webpage.



I was able to get all the urls from the webpage by using Python Selinum but not able to get the data under the map.



This is the sample URL. In google, I searched for "tool rental" and got the following url. In the following webpage there is a map, I was trying to get the data under the map.



URL:



https://www.google.com/search?q=tool+rental&rlz=1C1GCEA_en&oq=tool+rental&aqs=chrome.0.0l6.1735j0j7&sourceid=chrome&ie=UTF-8


MAP:



[![enter image description here][1]][1]



Desired Output:



The Rental Center at The Home Depot
Northside Tool Rental
Northside Tool Rental


I tried different options(find_eliment_by_xpath, find_eliment etc) to get the above data but nothing working.



The following code I was using to get the urls and data from maps.



from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By


driver = webdriver.Firefox(executable_path=r'C:ChaituProjectsMedia Marketingbrightlocalgeckodriver.exe')
driver.get("https://www.google.com/search?q=tool+rental&rlz=1C1GCEA_en&oq=tool+rental&aqs=chrome.0.0l6.1735j0j7&sourceid=chrome&ie=UTF-8")
driver.save_screenshot('image.png')

element=driver.find_element_by_tag_name('body')
element_png = element.screenshot_as_png
with open("test2.png", "wb") as file:
file.write(elem



[ad_2]

لینک منبع