【发布时间】:2016-01-23 10:49:12
【问题描述】:
我得到了以下标签:
<span class="one two-l three-project">not interested in</span>
<span class="one two-xl">interesting 1</span>
<span class="one two-l">interesting 2</span>
如何选择 2 个较低的跨度而不选择第一个?
我试过了:
html.find_all('span', attrs={'class' : re.compile(r'(one two-)'}) // doesn't select anything
html.find_all('span', attrs={'class' : re.compile(r'(?!three-project)')}) // does select all
html.find_all('span', attrs={'class' : 'one two-xl')}) // doesn't select the 3rd one
html.select('span.one.two-xl') // doesn't select the 3rd one
任何想法都非常感谢:-)
【问题讨论】:
-
不幸的是,bs4 将“one two-l three-project”解释为不是一个完整的大字符串,而是 3 个字符串(one、two-l 和 three-project)。因此“one two-x?l(?!three-project)”根本不匹配。
-
Beautifulsoup 不是很擅长这种东西,你想要什么lxml.de,文中有什么独特的地方可以用吗?
标签: python regex class beautifulsoup