美文网首页
正则匹配

正则匹配

作者: 戒灵 | 来源:发表于2018-12-14 15:12 被阅读0次

1,字符串匹配括号里内容

import re
s = "四五星(9)"
x = re.findall(r'[^()]+', s)[1]
print(x)
#输出:9
import re
s = "四五星(iii)(3333)"
x = re.findall(r'[^()]+', s)[2]
print(x)
#输出:3333

2,匹配以window.wingxViewData[0]= 开头 </script>结尾之间的内容

 text = re.findall(r'window.wingxViewData\[0\]=(.*)</script>',response.text)
 json_text = json.loads(text[0])

相关文章

网友评论

      本文标题:正则匹配

      本文链接:https://www.haomeiwen.com/subject/ozdghqtx.html