我想從使用BeautifulSoup的文章中提取圖像url和圖像標題。我可以從前面和後面的HTML中分離文章的圖片url和圖片標題,但我無法弄清楚如何將這兩個html標籤分開。這裏是我的代碼:使用BeautifulSoup提取圖像標題和圖像URL
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 =節。任何想法如何完成這兩個解析將不勝感激。
@Bill如果它解決了您的問題。請接受答案 –
這工作完美。非常感謝你。 –
正確的標記是'html5lib'而不是'lxml',用於'xml' –