简体   繁体   English

如何使用selenium获取javascript结果?

[英]How do I get javascript results using selenium?

I have the following code: 我有以下代码:

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)

The click executes a javascript file which then produces results on the same page. 点击执行一个javascript文件,然后在同一页面上生成结果。 Obviously print(text) will only print the orignal html source. 显然print(text)只会打印orignal html源代码。 How do I get to the results of the javascript? 我如何获得javascript的结果?

试试这个来获取id = your-id的html元素的内容:

sel.get_eval("this.browserbot.getCurrentWindow().document.getElementById('your-id').innerHTML"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JavaScript将“dragAndDrop”与Selenium一起使用? - How do I get “dragAndDrop” to work with Selenium using JavaScript? 如何使用 javascript 获取所选 Selenium WebElement 的 innerHTML? - How do I get the innerHTML of the selected Selenium WebElement using javascript? 如何在 Java selenium 中使用 JavascriptExecutor 获得 Javascript 的响应或如何提取<script> tag text? - How do I get response of Javascript using JavascriptExecutor in Java selenium or how to extract <script> tag text? 如何在Selenium中使用Javascript在html select中获取选项列表? - How do I get a list of options in an html select using Javascript in Selenium? 如何从Selenium获取JavaScript值? - How do I get JavaScript Values from Selenium? 如何使用selenium将javascript文件加载到DOM中? - How do I load a javascript file into the DOM using selenium? 如何使用 selenium 在 python 中执行 JavaScript 代码? - How do I execute a JavaScript code in python using selenium? 如何使用javascript附加字符串以形成结果? - How do I append a string to form results using javascript? 如何使用Sequelize和Javascript返回查询结果? - How do I return the results of a query using Sequelize and Javascript? 如何使用Python和Selenium获得链接的onclick“操作”? - How do I get the onclick “action” of a link using Python and Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM