【问题标题】:Web scraper with Python (BeautifulSoup 4) doesn't work使用 Python (BeautifulSoup 4) 的网络爬虫不起作用
【发布时间】:2016-01-23 20:01:58
【问题描述】:

问题是我不知道该怎么做。我正在尝试打印

与类 .first-text 并打印整个 HTML。如何使用 BeatifulSoup 4 打印它?

import requests
from bs4 import BeautifulSoup

html = requests.get("http://lifehacker.com/this-video-explains-how-to-survive-a-free-falling-eleva-1738366697").text
soup = BeautifulSoup(html)
p = soup.p
meow = soup.find(p['class'] == "first-text")
if meow:
    print(meow)
else:
    print(404)

【问题讨论】:

    标签: python web-scraping beautifulsoup


    【解决方案1】:

    您正在解析 find 函数中的逻辑表达式,调用应该如下所示。

    meow = soup.find('p', class="first-text")
    

    通常您应该查看文档以获取此类信息,您会找到一组很好的示例以及如何使用它的说明

    【讨论】:

      猜你喜欢
      • 2015-05-12
      • 1970-01-01
      • 2012-04-22
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      相关资源
      最近更新 更多