如何使用selenium获取javascript结果?

时间:2010-03-18 12:17:30

标签: javascript python selenium

我有以下代码:

from selenium import selenium

selenium = selenium("localhost", 4444, "*chrome", "http://some_site.com/")
selenium.start()

sel = selenium
sel.open("/")
sel.type("ctl00_ContentPlaceHolder1_SuburbTownTextBox", "Adelaide,SA,5000")
sel.click("ctl00_ContentPlaceHolder1_SearchImageButton")

#text = sel.get_body_text()
text = sel.get_html_source()

print(text)

点击执行javascript文件,然后在同一页面上生成结果。显然print(text)只会打印orignal html源代码。我如何获得javascript的结果?

1 个答案:

答案 0 :(得分:4)

尝试使用id = your-id:

获取html元素的内容
sel.get_eval("this.browserbot.getCurrentWindow().document.getElementById('your-id').innerHTML"