python - 使用 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 页面而不起作用吗?
解决方案
作为一个 ASPX 页面应该没有什么不同,因为底层页面源仍然是html
. 话虽这么说,您可能应该使用html.parser
而不是lxml
在BeautifulSoup
构造函数中。
脚本不返回结果的原因是页面源中没有您在函数html
中指定的类的匹配项。find_all
您应该查看页面源以确定要使用的正确关键字。
推荐阅读
- python - 循环中引用的 Django ManyToManyField
- gatsby - How do you host a gatsby site under a subpath
- python - 连接数据帧python
- javascript - 如何使用 change.type ==" added' 从 Firebase Firestore 获取实时文档更新
- java - Setting Timeout in URL Connection - Force Server to Finish Reading Data with Method Similar to HttpURLConnection.setReadTimeout()
- regex - How can I check regex for three patterns in one
- swift - 排列 - DFS 和回溯 - 需要帮助理解展开和回溯
- amazon-web-services - S3 通知在其他区域调用 sqs 主题
- python - Python help to update Postgres column
- demandware - Commerce Cloud - 如何覆盖“应用”按钮的代码?