我正在使用Python绑定来运行Selenium WebDriver.
from selenium import webdriver
wd = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
我知道我可以抓住这样的一个元素......
elem = wd.find_element_by_css_selector('#my-id')
Run Code Online (Sandbox Code Playgroud)
而且我知道我可以获得完整的页面来源...
wd.page_source
Run Code Online (Sandbox Code Playgroud)
但无论如何要获得"元素来源"?
elem.source # <-- returns the HTML as a string
Run Code Online (Sandbox Code Playgroud)
用于Python的selenium webdriver文档基本上不存在,我在代码中看不到任何似乎启用该功能的内容.
有关访问元素(及其子元素)的HTML的最佳方法的任何想法?
python selenium automated-tests webdriver selenium-webdriver
我有使用xpath爬行的HTML网页.在etree.tostring某个节点的给我这个字符串:
<script>
<!--
function escramble_758(){
var a,b,c
a='+1 '
b='84-'
a+='425-'
b+='7450'
c='9'
document.write(a+c+b)
}
escramble_758()
//-->
</script>
Run Code Online (Sandbox Code Playgroud)
我只需要输出escramble_758().我可以写一个正则表达式来弄清楚整个事情,但我希望我的代码保持整洁.什么是最好的选择?
我正在浏览以下库,但我没有看到确切的解决方案.他们中的大多数都试图模仿浏览器,使事情变得缓慢.
it's not yet possible to call a function defined in Javascript)编辑:一个例子将是伟大的..(准系统会做)
我想使用Python使用Selenium 登录此页面.但是浏览器中显示的页面与HTML中描述的页面不同.Firefox或Chrome webdriver获得相同的结果.
chromedriver = "./chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
# OR
#driver = webdriver.Firefox()
driver.get('http://www.anb.org/login.htmlurl=%2Farticles%2Fhome.html&ip=94.112.189.79&nocookie=0')
# get screenshot of page
driver.get_screenshot_as_file('./01.png')
#get source code of page
print driver.page_source
Run Code Online (Sandbox Code Playgroud)
我不允许发布图像,但图像与Web浏览器中显示的页面完全相同.
驱动程序的HTML代码:
<html><head>
<title>American National Biography Online</title>
<script>
document.write ("<FRAMESET ROWS=\"103,*\" FRAMEBORDER=0 BORDER=0 FRAMESPACING=0>\n");
document.write (" <FRAME SRC=\"top-home.html\" MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=NO>\n");
if (location.search) {
var url = unescape (location.search);
url = (new String(url)).substring(1);
if (url.indexOf ("&") == -1) {
document.write (" <FRAME SRC=\"" + url + "\" …Run Code Online (Sandbox Code Playgroud)