简体   繁体   English

使用Python和BeautifulSoup在字符串中获取正则表达式1-10的问题

[英]Issue getting regex for 1-10 in string using Python and BeautifulSoup

I'm having trouble figuring out what I need to do to get this regex into a string. 我在弄清楚将此正则表达式转换为字符串所需要做的事情。 A page has 10 divs, named info1, info2, info3, etc., through info10. 一个页面有10个div,分别通过info10命名为info1,info2,info3等。

Here's what I've got but for some reason that'll seem obvious it's not working. 这就是我所拥有的,但是由于某种原因,它似乎不起作用。

data = soup.findAll("div", {"id":"info(r'\d+')}

You need to provide a compiled regular expression pattern : 您需要提供一个已编译的正则表达式模式

import re

data = soup.find_all("div", {"id": re.compile(r"info\d+")}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM