Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在Selenium和Firefox中检索原始JSON数据?_Python_Selenium_Firefox_Selenium Firefoxdriver - Fatal编程技术网

Python 如何在Selenium和Firefox中检索原始JSON数据?

Python 如何在Selenium和Firefox中检索原始JSON数据?,python,selenium,firefox,selenium-firefoxdriver,Python,Selenium,Firefox,Selenium Firefoxdriver,如何使用Selenium和Firefox webdriver从web请求中获取原始JSON文本 我正在尝试测试JSON API,并确认特定数据是通过Firefox的Python Selenium接口返回的。如果我在Chrome中查看URL的页面源,我会看到如下内容: {"id":10472} 但是,如果我在Selenium+Firefox中调用相同的URL,并通过json\u text=self.driver.page\u source访问文档的源代码,我会得到: <html platf

如何使用Selenium和Firefox webdriver从web请求中获取原始JSON文本

我正在尝试测试JSON API,并确认特定数据是通过Firefox的Python Selenium接口返回的。如果我在Chrome中查看URL的页面源,我会看到如下内容:

{"id":10472}
但是,如果我在Selenium+Firefox中调用相同的URL,并通过
json\u text=self.driver.page\u source
访问文档的源代码,我会得到:

<html platform="linux" class="theme-light" dir="ltr"><head><meta http-equiv="Content-Security-Policy" content="default-src 'none' ; script-src resource:; "><link rel="stylesheet" type="text/css" href="resource://devtools-client-jsonview/css/main.css"></head><body><div id="content"><div id="json">{"id":10472}</div></div><script src="resource://devtools-client-jsonview/lib/require.js" data-main="resource://devtools-client-jsonview/viewer-config.js"></script></body></html>
{“id”:10472}

看起来Firefox正在检测JSON内容类型,并试图通过将其包装在一个奇特的HTML UI中来“帮助”my。不幸的是,这使得从Selenium以编程方式提取和验证JSON变得困难。如何禁用此功能?

为什么不使用json定位
WebElement

self.driver.find_element_by_id('json').text # {"id":10472}