I'm trying to scrape the text "Woodford Reserve Master Collection Five Malt Stouted Mash" from the following:
<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>
I am able to scrape the href using the following code, however can't seem to be able to scrape the title text separately:
for product in soup.select('a.catalog_item_name'):
link.append(product['href'])
print(link)
I have also tried
for product in soup.select('a.catalog_item_name'):
link.append(product.a['href'])
print(link)
However I can't seem to quite capture the title information separately. Thanks in advance for the help!
CodePudding user response:
Try:
data=[]
for product in soup.select('a.catalog_item_name'):
link=product['href']
title=product.get_text()
data.append([link,title])
print(data)