mengmei886 发表于 2020-3-29 15:48:31

beautifulsoup提取script中内容

本帖最后由 mengmei886 于 2020-3-29 15:49 编辑

<html>前面一大堆html内容省略。。。</html>html>
<script>前面好多script</script>
<script>
    var vm = new Vue({
      el: '#listApp',
      data: function () {
            return {
                activeLog: "first",
                uploadDir: '',
                isCS: "0",
                loading: true,
                hasCollected: true,
                titles: "添加",
                isShow: ("1" != '2' && ("910" == "1234" || false)) ? true : false,
                listQuery: {
                  bizId: "10020",
                  clueId: "129300co",
                  contactUnitId: "929537",
                  contentId: "222999",
                  clueType: "1012",
                  supPageNum: 1,
                },
                logQuery: {
                  bizId: "10020",
                  clueId: "129300co",
                  contentId: "222999",
                  clueType: "1012",
                  pageNum: 1,
                  numPerPage: 10,
                  contentKey: ''
                },
                }}})
</script>   
<script type="text/javascript">省略</script>
<script>好多script</script>
<script>好多script</script>


求助各位大佬,这是python爬的网站内容,我怎么样才能将其中的一个<script>中的listQuery提取出来呢?使用beautifulsoup和正则应该怎么写?
也就是我只想要
listQuery: {
                  bizId: "10020",
                  clueId: "129300co",
                  contactUnitId: "929537",
                  contentId: "222999",
                  clueType: "1012",
                  supPageNum: 1,
                }
或者{}中的内容,感谢各位大佬

flamezyy 发表于 2020-3-29 16:18:03

re.search(r'(listQuery: .*?\}),', a, re.DOTALL).group(1)
a就是原始字符,正则真的很方便

mengmei886 发表于 2020-3-29 16:25:26

flamezyy 发表于 2020-3-29 16:18
a就是原始字符,正则真的很方便

膜拜大佬,可以了,谢谢!!!
页: [1]
查看完整版本: beautifulsoup提取script中内容