zoukankan      html  css  js  c++  java
  • python爬取动态页面

    有些你想爬取的页面数据并不在html里,而是由js动态加再出来,所以xpath不能提取出想要的数据,有些需要用到正则表达式,例如爬取丁香园疫情数据:

    import requests
    import re
    import json
    
    reault=requests.get('https://ncov.dxy.cn/ncovh5/view/pneumonia?scene=2&clicktime=1579583352&enterid=1579583352&from=timeline&isappinstalled=0')
    
    url_text=reault.content.decode()
    url_result=re.search(r'window.getAreaStat = (.*?)}]}catch',url_text,re.S)
    texts=url_result.group()
    
    texts=texts.replace('window.getAreaStat = ','')
    texts=texts.replace('}catch','')
    c=json.loads(texts)
    print(c)
  • 相关阅读:
    父子组件例子
    指令
    使用git将代码推到coding
    vue生命周期
    vue 父子组件
    vuex
    使用vue与element组件
    vue02
    使用vue
    telnet 使用
  • 原文地址:https://www.cnblogs.com/yuanxiaochou/p/12307638.html
Copyright © 2011-2022 走看看