【问题标题】:How to select a div within a nested div's using beautifulsoup?如何使用beautifulsoup在嵌套的div中选择一个div?
【发布时间】:2021-11-28 07:45:09
【问题描述】:

我无法访问这么多嵌套 div 中的 div。 . . .

<div class="list-card-price">$2,600/mo</div>

。 . .

我正在使用这种方法来检索它:

from bs4 import BeautifulSoup
import requests
import lxml

response = requests.get(url="https://www.zillow.com/homes/for_rent/1-_beds/?.....")
data = response.text

soup = BeautifulSoup(data,"lxml")

price_list = []

price_tag = soup.select_one(name='div',class_="list-card-price")
print(price_tag)

【问题讨论】:

    标签: python web-scraping beautifulsoup


    【解决方案1】:

    会发生什么?

    1. 始终深入了解您的soup - 这是事实!它带有验证码警告。

    2. 您的选择将引发错误,因为您混合使用 find()select_one() 的语法

    如何解决?

    1. 仔细看看这个答案options to deal with captcha

    2. 将您的选择更改为soup.select_one('div.list-card-price') 以避免出现错误TypeError: select_one() missing 1 required positional argument: 'selector'

    【讨论】:

      【解决方案2】:

      您可以使用“soup.text”检查在汤中发送的 HTML。当我运行代码时,网站向请求模块显示了一个验证码页面,而不是实际的网页。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-09
        • 2022-11-14
        • 1970-01-01
        • 2019-04-10
        • 1970-01-01
        • 1970-01-01
        • 2017-07-24
        相关资源
        最近更新 更多