首页 > 解决方案 > 使用 Python 抓取 ASPX 页面

问题描述

我正在尝试浏览一个 aspx 网站。我的脚本只是产生:

[]

进程以退出代码 0 结束

我的代码如下:

import requests
import bs4



url = "https://www.brightmlshomes.com/Listing/ListingSearch.aspx"

page = requests.get(url)

src = page.text

soup = bs4.BeautifulSoup(src, 'lxml')

final_results = []

for tmp in soup.find_all('div', {'class': 'mapsearch-singleprop mapsearch-map-singleprop included '
                                         'slick-already-processed'}):

    final_results.append(tmp['data-price'])

print(final_results)

这是因为它是 ASPX 页面而不起作用吗?

标签: pythonweb-scraping

解决方案


作为一个 ASPX 页面应该没有什么不同,因为底层页面源仍然是html. 话虽这么说,您可能应该使用html.parser而不是lxmlBeautifulSoup构造函数中。

脚本不返回结果的原因是页面源中没有您在函数html中指定的类的匹配项。find_all您应该查看页面源以确定要使用的正确关键字。


推荐阅读