您好,我正在尝试从HTML页面检索第3个HREF标记。但是下面的代码不会返回任何结果。任何提示/答案是真的我试图解析useful.The网址如下:无法从标记中检索HREF
http://pr4e.dr-chuck.com/tsugi/mod/python-data/data/known_by_Fikret.html
代码是这样的:
# This python code will parse an html and
# find href content from a particular position
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',limit=3)[2]
for tag in tags:
print tag.get('href', None)
我是初学者,通过Coursera学习Python。这是一个任务,所以我宁愿提示或任何线索,我要去哪里错了,而不是直接的答案:)谢谢! –
发布'tags'变量的输出.. –
最好在Coursera论坛上询问以帮助您。 – Valijon