我正在嘗試從以下內容中洗掉文本“Woodford Reserve Master Collection Five Malt Stouted Mash”:
<a aria-hidden="true" tabindex="-1" id="WC_CatalogEntryDBThumbnailDisplayJSPF_3074457345616901168_link_9b" href="/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10051&storeId=10051&productId=3074457345616901168&langId=-1&partNumber=000086630prod&errorViewName=ProductDisplayErrorView&categoryId=1334014&top_category=25208&parent_category_rn=1334013&urlLangId=&variety=American Whiskey&categoryType=Spirits&fromURL=/webapp/wcs/stores/servlet/CatalogSearchResultView?storeId=10051&catalogId=10051&langId=-1&categoryId=1334014&variety=American+Whiskey&categoryType=Spirits&top_category=&parent_category_rn=&sortBy=5&searchSource=E&pageView=&beginIndex=">Woodford Reserve Master Collection Five Malt Stouted Mash</a>
我可以使用以下代碼抓取 href,但似乎無法單獨抓取標題文本:
for product in soup.select('a.catalog_item_name'):
link.append(product['href'])
print(link)
我也試過
for product in soup.select('a.catalog_item_name'):
link.append(product.a['href'])
print(link)
但是,我似乎無法單獨捕獲標題資訊。在此先感謝您的幫助!
uj5u.com熱心網友回復:
嘗試:
data=[]
for product in soup.select('a.catalog_item_name'):
link=product['href']
title=product.get_text()
data.append([link,title])
print(data)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478738.html
上一篇:為什么我的請求沒有得到回應?
下一篇:似乎無法從網頁中抓取特定資訊?
