2017-06-05 61 views
0

我使用selenium和ChromeDriver来测试XML响应。在Selenium Chrome驱动程序中获取真实的XML源代码

的反应是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<d>test</d> 

但如果我get该URL的硒,铬会自动呈现XML,使得page_source脏。

>>> from selenium import webdriver 
>>> b=webdriver.Chrome() 
>>> b.get('http://127.0.0.1/test.xml') 
>>> b.page_source 
'<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml"><head><style id="xml-viewer-style">/* Copyright 2014 The Chromium Authors. All rights reserved.\n * Use of this source code is governed by a BSD-style license that can be\n * found in the LICENSE file...' 

(你可以看到Chrome浏览器添加一个“XML查看”页面源)

什么是让XML的真正来源的最佳做法?

ps。这个XML是由铬扩展返回的,我将使用硒进行测试,因此“使用requestsurllib”不是一个解决方案。

回答

0

好吧,我的解决办法是:

b.execute_script('return document.getElementById("webkit-xml-viewer-source-xml").innerHTML') 

这当然不是一个很好的做法,但至少工作。

相关问题