如何从硒python中的JSON中获取 [英] how to grab from JSON in selenium python

查看:83
本文介绍了如何从硒python中的JSON中获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面返回JSON http响应,其中包含ID:14

My page returns JSON http response which contains id: 14

Selenium python中有一种方法可以抓到这个吗?我在网上搜索,找不到任何解决方案.现在,我想知道这是不可能的吗?我可以从数据库中获取此ID,但是我试图避免这种情况.请告诉我是否有任何办法.谢谢

Is there a way in selenium python to grab this? I searched the web and could not find any solutions. Now I am wondering maybe its just not possible? I could grab this id from the db but I am trying to avoid this. Please tell me if there is any ways around. Thank you

推荐答案

您可以使用BeautifulSoup解析页面并提取json.您所需的代码应如下所示.如果json不在响应的正文中,则可能需要更改soup.find命令.

You can use BeautifulSoup to parse the page and extract the json. The code you need should look something like this. You may need to change the soup.find command if the json isn't directly in the body of the response.

from bs4 import BeautifulSoup
import json

soup = BeautifulSoup(driver.page_source)
dict_from_json = json.loads(soup.find("body").text)

这篇关于如何从硒python中的JSON中获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆