python 我们如何从Zillow获得卧室面积和价格?[关闭]

wgx48brx  于 2023-05-27  发布在  Python
关注(0)|答案(2)|浏览(175)

**已关闭。**此问题正在寻求书籍、工具、软件库等的建议。它不符合Stack Overflow guidelines。目前不接受答复。

我们不允许问题寻求书籍,工具,软件库等的建议。您可以编辑问题,以便可以用事实和引用来回答。
1小时前关闭
Improve this question
我今天在下面向ChatGPT提出了这个问题

'User python mozlla headers scrape bedrooms square footage and price from zillow'

我来搞定

import requests
from bs4 import BeautifulSoup

# Set the URL of the Zillow page you want to scrape
url = "https://www.zillow.com/breckenridge-co/sold/?searchQueryState=%7B%22pagination%22%3A%7B%7D%2C%22usersSearchTerm%22%3A%22Breckenridge%2C%20CO%22%2C%22mapBounds%22%3A%7B%22west%22%3A-106.12936606713866%2C%22east%22%3A-105.9443151027832%2C%22south%22%3A39.45416110834031%2C%22north%22%3A39.497489978187815%7D%2C%22regionSelection%22%3A%5B%7B%22regionId%22%3A14934%2C%22regionType%22%3A6%7D%5D%2C%22isMapVisible%22%3Atrue%2C%22filterState%22%3A%7B%22sort%22%3A%7B%22value%22%3A%22days%22%7D%2C%22fsba%22%3A%7B%22value%22%3Afalse%7D%2C%22fsbo%22%3A%7B%22value%22%3Afalse%7D%2C%22nc%22%3A%7B%22value%22%3Afalse%7D%2C%22fore%22%3A%7B%22value%22%3Afalse%7D%2C%22cmsn%22%3A%7B%22value%22%3Afalse%7D%2C%22auc%22%3A%7B%22value%22%3Afalse%7D%2C%22rs%22%3A%7B%22value%22%3Atrue%7D%2C%22ah%22%3A%7B%22value%22%3Atrue%7D%7D%2C%22isListVisible%22%3Atrue%2C%22mapZoom%22%3A13%7D"

# Send an HTTP GET request to the URL
response = requests.get(url)

# Create a BeautifulSoup object to parse the HTML content
soup = BeautifulSoup(response.content, "html.parser")

# Find the relevant elements containing the data you want to scrape
results = soup.find_all("article", class_="property-card-data")

# Loop through each result and extract the desired information
for result in results:
    # Extract the bedroom information
    bedrooms = result.find("ul", class_="list-card-details").find("li").text.strip()

    # Extract the square footage
    square_footage = result.find("ul", class_="list-card-details").find_all("li")[1].text.strip()

    # Extract the price
    price = result.find("div", class_="list-card-price").text.strip()

    # Print the scraped data
    print("Bedrooms:", bedrooms)
    print("Square Footage:", square_footage)
    print("Price:", price)
    print()

问题是,什么都没有返回。我认为问题在于'soup.find_all'或'class_='。这到底是怎么回事有人能给我解释一下吗我正在学习这个概念。谢谢。

r7s23pms

r7s23pms1#

这是在Zillow网站的常见问题部分
问:我们可以检索和存储Zillow数据吗?
答:不可以。您只能使用API检索和显示Zillow的动态内容。不允许您在本地存储信息。
问:我们可以不使用API,而是反向工程数据馈送或手动从Zillow提取信息吗?
答:不可以。我们只允许第三方通过API从我们的网站检索数据。任何用于直接提取数据而不使用Zillow API的逆向工程、蜘蛛或其他技术都违反了我们的使用条款。
使用您的代码连接到该URL的响应是一个验证码,它希望验证执行搜索的人。

9njqaruj

9njqaruj2#

@kevin-schlosser的答案是正确的。为了学习这些概念,请尝试在控制台中逐行运行代码,并查看每行返回的内容

>>> response = requests.get(url)
>>> print (response)
<Response [403]>

相关问题