0
我正在尋找在Python中返回以下所有實例,但不知道如何。如,我怎麼可以搜索字符串並打印每個以下格式發現時間:如何在Python中查找字符串中的模式/組合?
<a href="[what I'm trying to return is here]" class="faux-block-link__overlay-link"
我正在尋找在Python中返回以下所有實例,但不知道如何。如,我怎麼可以搜索字符串並打印每個以下格式發現時間:如何在Python中查找字符串中的模式/組合?
<a href="[what I'm trying to return is here]" class="faux-block-link__overlay-link"
你需要一個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
提供了一個方便的詞典式訪問元素屬性。
非常感謝。 –
@Security:請閱讀[_當有人回答我的問題時我應該怎麼做?](http://stackoverflow.com/help/someone-answers) – martineau
@martineau:對不起,這裏很新。謝謝你讓我知道。 –