Skip to content Skip to sidebar Skip to footer

Find Specific Text Within Html Tag In Python

I've tried a million different ways to parse out the zestimate, but have yet to be successful. here's the html tag with the zestimate info:

Solution 1:

To get correct HTML from the site, add User-Agent header to request.

For example:

import requests
from bs4 import BeautifulSoup


url = 'https://www.zillow.com/homedetails/1404-Clearwing-Cir-Georgetown-TX-78626/121721750_zpid/'
headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:77.0) Gecko/20100101 Firefox/77.0'}
soup = BeautifulSoup(requests.get(url, headers=headers).content, 'html.parser')

home_value = soup.select_one('h4:contains("Home value")').find_next('p').get_text(strip=True)
print(home_value)

Prints:

$331,425

Post a Comment for "Find Specific Text Within Html Tag In Python"