I am a building restoration student and I am learning to scrape. I am working on the collection of data from churches in Spain. For this I am working with the Catastro website. I'm collecting the data and I'm having trouble getting the src of the images.
Next, I put a part of the code that I have created throws me an error in the # Get the URL of the image part. When I access from the browser manually if I am able to find the image but I can't find the way to do it with Selenium. Could it be because the element is in a nested ::before
?
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
# Start a webdriver session using Firefox
driver = webdriver.Firefox()
# Go to the website
driver.get("https://www1.sedecatastro.gob.es/Cartografia/mapa.aspx?refcat=9271101WJ9197A&from=OVCBusqueda&pest=rc&final=&RCCompleta=9271101WJ9197A0001BR&ZV=NO&ZR=NO&anyoZV=&tematicos=&anyotem=&del=2&mun=900")
# Wait until the map element is present and click on its center
map_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//*[@id="map"]'))
)
driver.execute_script("arguments[0].scrollIntoView(true);", map_element)
map_element.click()
# Get the URL of the image
img_element = driver.find_element_by_xpath('//*[@id="ImgFachada0"]')
# Get the src attribute of the image element
img_src = img_element.get_attribute("src")
# Print the src of the image
print(img_src)