[英]How to extract href link from a <li class='item'> tag?
Python 實現
soup = BeautifulSoup(html_doc, 'html.parser')
linkList = []
aList = []
for liNode in soup.find_all('li'):
for aNode in liNode.find_all('a'):
aList.append(aNode)
linkList.append(aNode.get('href'))
所以在aNode
里面你有完整的 HTML Object 而在linkList
里面你只有鏈接。
@marlon 對於來自鏈接的 HTML object,您可以這樣做:
for link in linkList:
with open(link) as fp:
soup1 = BeautifulSoup(fp, 'html.parser')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.