0

How can I get the data from the following tag:

<a class="sc-bdVaJa ebNrSm" href="/inmueble/venta-apartamento-bogota-puente-largo-2-habitaciones-2-banos-2-garajes/14221-M3963321" target="_blank" data-gtm-productname="Apartamento en Venta, Puente Largo, Bogotá D.C." data-gtm-productsku="14221-M3963321" data-gtm-productprice="457000000" data-gtm-productcategory="venta - Apartamento" data-gtm-city="Bogotá D.C." data-gtm-zone="Noroccidente" data-gtm-neighborhood="PUENTE LARGO" data-gtm-businesstype="venta" data-gtm-propertytype="Apartamento" data-gtm-projectname="Ocasional" data-gtm-position="1"\><h2 class="sc-dxgOiQ BSoGx card-title"\><div\>Apartamento en Venta, Puente Largo, Bogotá D.C.</div\></h2\></a\>

i try:

import requests
from bs4 import BeautifulSoup


url = 'https://www.metrocuadrado.com/apartamento/venta/bogota/?search=form'
page = requests.get(url)

soup = BeautifulSoup(page.content, 'lxml')

projects = soup.find('a', class_='sc-bdVaJa ebNrSm')
print(projects.text)

but, i get error: AttributeError: 'NoneType' object has no attribute 'text'

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Should `class_` be `class`? Looks like you're also missing a closing quote on that line. (Not sure how you're able to get an `AttributeError` running this code since it should instead raise a `SyntaxError` before anything is executed...) – Samwise Jan 03 '23 at 00:43
  • @Samwise Obviously a copying error. – Barmar Jan 03 '23 at 00:50

0 Answers0