【发布时间】:2010-09-22 02:31:32
【问题描述】:
给定一个 HTML 链接,例如
<a href="urltxt" class="someclass" close="true">texttxt</a>
如何隔离 url 和文本?
更新
我正在使用 Beautiful Soup,但我不知道该怎么做。
我做到了
soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(url))
links = soup.findAll('a')
for link in links:
print "link content:", link.content," and attr:",link.attrs
我明白了
*link content: None and attr: [(u'href', u'_redirectGeneric.asp?genericURL=/root /support.asp')]* ...
...
为什么我错过了内容?
编辑:按照建议详细说明“卡住”:)
【问题讨论】:
-
可能是 urllib.urlopen(url) 有问题。试着把它打印出来,看看你得到了什么。它应该是网页的直接 HTML。
-
还有,“卡住了!”不是很具有描述性。显示更多代码以及到底出了什么问题。
-
感谢您提供的额外信息,它让您更容易看到发生了什么。
标签: python html regex beautifulsoup