我相信你正設法從無序列表獨特的錨裏面你的div。你可以看到每個錨具有獨特的類,rel-ink
VS rel-name
:
<a href="//store.taobao.com/shop/view_shop.htm?user_number_id=2469022358" target="_blank" class="rel-ink"><img alt="NIHAOMARKET官方海外旗艦店" src="//img.alicdn.com/top/i1/TB1urimJFXXXXabaXXXwu0bFXXX.png" class="rel-img"></a>
<a href="//store.taobao.com/shop/view_shop.htm?user_number_id=2469022358" target="_blank" class="rel-name">NIHAOMARKET官方海外旗艦店</a>
所以,你可以使用錨類名第一錨每個李裏即REL-墨讓他們:
urls =[a["href"] for a in soup.find('div', id="success-case").find_all("a",class_="rel-ink")]
或使用CSS選擇:
urls = [a["href"] for a in soup.select("#success-case ul li a.rel-ink")]
兩者都會給你:
['//store.taobao.com/shop/view_shop.htm?user_number_id=692020965', '//store.taobao.com/shop/view_shop.htm?user_number_id=2087799889', '//store.taobao.com/shop/view_shop.htm?user_number_id=2469022358', '//store.taobao.com/shop/view_shop.htm?user_number_id=377676745', '//store.taobao.com/shop/view_shop.htm?user_number_id=2367059695', '//store.taobao.com/shop/view_shop.htm?user_number_id=449764134', '//store.taobao.com/shop/view_shop.htm?user_number_id=698389964', '//store.taobao.com/shop/view_shop.htm?user_number_id=509711360', '//store.taobao.com/shop/view_shop.htm?user_number_id=692020965', '//store.taobao.com/shop/view_shop.htm?user_number_id=1125022434', '//store.taobao.com/shop/view_shop.htm?user_number_id=1071997040', '//store.taobao.com/shop/view_shop.htm?user_number_id=795947607', '//store.taobao.com/shop/view_shop.htm?user_number_id=509711360', '//store.taobao.com/shop/view_shop.htm?user_number_id=692020965', '//store.taobao.com/shop/view_shop.htm?user_number_id=1071997040', '//store.taobao.com/shop/view_shop.htm?user_number_id=509711360', '//store.taobao.com/shop/view_shop.htm?user_number_id=377676745', '//store.taobao.com/shop/view_shop.htm?user_number_id=2367059695', '//store.taobao.com/shop/view_shop.htm?user_number_id=2469022358']
你可以嘗試澄清?你有什麼?你想得到什麼? –
我想要獲取特定的HTML屬性,在這種情況下,如果元素沒有文本,它將是中的IMG URL。 – Dilli