weixin_33735077 2018-10-10 17:58 采纳率: 0%
浏览 32

Python 3:检测Ajax查询

I try to scrape some websites with the help of Python and BeautifulSoup.
When a website uses an ajax query with this kind of URL:

https://techcrunch.com/wp-json/tc/v1/magazine?page=2&_embed=true,

I can get the JSON content and analyze it. But how can I detect this links to automatically execute a query to get the JSON content?

Thanks, Rata

  • 写回答

1条回答 默认 最新

  • weixin_33725722 2018-10-10 18:17
    关注

    I recommend using the requests library in addition to BeautifulSoup, if you aren't already.

    Assuming you have a reliable way to scrape these urls, you can do something like:

        import requests
    
        # ...
    
        response = requests.get('https://techcrunch.com/wp-json/tc/v1/magazine?page=2&_embed=true')
    
        try:
          json_response = response.json()
          # GET request returned a JSON response
          # ...
    
        except ValueError:
          # GET request did not return JSON response
          # ...
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度