2016-05-08 110 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:對不起,這裏很新。謝謝你讓我知道。 –