【发布时间】:2016-10-12 22:41:33
【问题描述】:
我正在使用以下代码使用 BeautifulSoup 检索一堆链接。它返回所有链接,但我想获取第三个链接,解析那个链接,然后从那个链接中获取第三个链接,依此类推。如何修改下面的代码来实现这一点?
import urllib
from BeautifulSoup import *
url = raw_input('Enter - ')
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
print tag.get('href', None)
print tag.contents[0]
【问题讨论】:
标签: python python-2.7 beautifulsoup