想象我有内容,如:捕获IDS与XPath在Python从URL源
cont="""<a id="test1" class="SSSS" title="DDDD" href="AAAA">EXAMPLE1</a>.....<a id="test2" class="GGGG" title="ZZZZ" href="VVVV">EXAMPLE2</a>....
"""
我想要什么:
id1='test1'
id2='test2'
idn='testn'
你能纠正我?
if '<a id=' in cont:
....?
我一定要使用正则表达式在 Python或有通过的XPath的方法来抓住他们?
注:我只希望在标签
为什么不使用类似Bsoup或lxml的东西? – 2014-11-06 08:11:35
Beautifulsoup似乎确实是一个简单的方法来做到这一点:http://www.crummy.com/software/BeautifulSoup/bs4/doc/ – 2014-11-06 08:12:43
@Vincent Beltman如果你知道一个可靠的方法,它会受到欢迎... – MLSC 2014-11-06 08:12:45