2016-05-08 109 views

回答

1

你需要一个HTML解析器,像BeautifulSoup。示例:

>>> from bs4 import BeautifulSoup 
>>> 
>>> s = '<a href="[what I\'m trying to return is here]" class="faux-block-link__overlay-link">link</a>' 
>>> BeautifulSoup(s, "html.parser").a["href"] 
u"[what I'm trying to return is here]" 

其中.a相当于.find("a")。请注意,BeautifulSoup提供了一个方便的词典式访问元素属性。

+1

非常感谢。 –

+1

@Security:请阅读[_当有人回答我的问题时我应该怎么做?](http://stackoverflow.com/help/someone-answers) – martineau

+0

@martineau:对不起,这里很新。谢谢你让我知道。 –