很抱歉,如果您以前遇到过这个问题,我发现python regex文档很难理解,主要是因为缺少示例。 我想抓取一个页面源代码块,稍后再进行解析。例如:
<div id="viewed"><div class="shortstory-block">
<div class="shortstoey-block-image">
<a href="...."><img src="/uploads/posts/cov.jpg" alt="instance 1"/></a>
<span class="format"><a href="http://www..../">something</a></span>
</div>
<a href="http://....."><span class="shortstory-block-title" style="text-decoration:none !important;">
Something
</span>
</a>
</div><div class="shortstory-block">
<div class="shortstoey-block-image">
<a href="...."><img src="/uploads/posts/cov.jpg" alt="something 2"/></a>
<span class="format"><a href="http://www.website/xfsearch/smth/">something</a></span>
</div>
<a href="http://web.html"><span class="shortstory-block-title" style="text-decoration:none !important;">
Something
</span>
</a>
</div>
(* x times)
<div id="rated">....
我把所有的页面源代码都放在一个变量(html\u源代码)中,我只想用这段代码定义另一个变量(在div^{id1}之间)$
有人能给我指出正确的方向(regex表达式)吗?你知道吗
提前谢谢
re.DOTALL
标志使。匹配任何字符。没有那面旗子,它就不符合新行。你知道吗(DOTALL也可以在regexp本身中拼写为
(?s)
)有关类似的问题,以及代码示例和更好的方法,请参见: Python's "re" module not working?
如果您确实只是想在文本的两个元素之间找到一些东西,可以使用以下正则表达式:
相关问题 更多 >
编程相关推荐