2
我試圖從BBC Good Food網站提取信息,但我收集的數據縮小了一些問題。如何用BeautifulSoup和Python刮頁?
這是我到目前爲止有:
from bs4 import BeautifulSoup
import requests
webpage = requests.get('http://www.bbcgoodfood.com/search/recipes?query=tomato')
soup = BeautifulSoup(webpage.content)
links = soup.find_all("a")
for anchor in links:
print(anchor.get('href')), anchor.text
這將返回從問題的網頁加上鍊接的文字描述的所有鏈接,但我想提取從「文章」類型對象的鏈接在頁面上。這些是特定配方的鏈接。
通過一些試驗,我已成功地返回從文章的內容,但我似乎無法提取鏈接。
非常感謝您! – jm22b 2015-04-03 09:53:46
沒有問題,不客氣。 – 2015-04-03 10:45:18