【发布时间】:2016-11-20 05:59:50
【问题描述】:
我正在使用 Beautiful Soup 4 来解析新闻站点以获取正文中包含的链接。我能够找到包含链接的所有段落,但 paragraph.get('href') 为每个链接返回类型 none。我正在使用 Python 3.5.1。非常感谢任何帮助。
from bs4 import BeautifulSoup
import urllib.request
import re
soup = BeautifulSoup("http://www.cnn.com/2016/11/18/opinions/how-do-you-deal-with-donald-trump-dantonio/index.html", "html.parser")
for paragraph in soup.find_all("div", class_="zn-body__paragraph"):
print(paragraph.get('href'))
【问题讨论】:
标签: python beautifulsoup