xpath中使用正则表达式
没想到吧 id 也可以模糊定位
比如有个网站正文部分是: //[@id='el-popover-123456']
另一个同级别页面的正文是: // [@id='el-popover-456789']
要抓取这种正文其实可以用xpath:
            
            
              python
              
              
            
          
           //*[starts-with(@id, 'el-popover-')]
        或者
            
            
              python
              
              
            
          
          //*[contains(@id, 'postmessage_')]
        也可以选择在xpath中使用正则表达式:
            
            
              javascript
              
              
            
          
          .xpath(r'//*[re:match(@id, "postmessage_\d+")]')