<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>
我该如何获取第一个和第二个段落标签之间的字符串?然后,我该如何获取第二个段落标签之间的字符串?
import re
matches = re.findall(r'<p>.+?</p>',string)
以下是您的文本在控制台中运行的内容。>>>import re
>>>string = """<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"""
>>>re.findall('<p>.+?</p>',string)
["<p>I'd like to find the string between the two paragraph tags.</p>", '<p>And also this string</p>']
import re
string = """<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"""
subStr = re.findall(r'<p>(.+?)</p>',string)
print subStr
结果
["I'd like to find the string between the two paragraph tags.", 'And also this string']
在<p>
和</p>
之间
In [7]: content = "<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"
In [8]: re.findall(r'<p>(.+?)</p>', content)
Out[8]:
["I'd like to find the string between the two paragraph tags.",
'And also this string']
</p>
。 - gonczorsplit = re.findall('<p>.+?</p>',content)
......second = split[1]
......它给了我一个“索引超出范围”的错误。我该如何获取第二个元素? - Zorgan>>> split = re.findall('
- Isdj(.+?)
',string) >>> split[1] 'And also this string'