【发布时间】:2017-09-17 11:58:06
【问题描述】:
我正在尝试使用 BeautifulSoup 从一篇文章中提取图片网址和图片标题。我可以将文章的图像 url 和图像标题与前后 HTML 分开,但我不知道如何将这两者与它们的 html 标签分开。这是我的代码:
from bs4 import BeautifulSoup
import requests
url = 'http://www.prnewswire.com/news-releases/dutch-philosopher-
koert-van-mensvoort-founder-of-the-next-nature-network-writes-a-
letter-to-humanity-619925063.html'
r = requests.get(url)
html = r.text
soup = BeautifulSoup(html, 'lxml')
links = soup.find_all('div', {'class': 'image'})
我试图提取的两个部分是 src= 和 title= 部分。任何关于如何完成这两个解析的想法都将不胜感激。
【问题讨论】:
标签: python html parsing beautifulsoup