我在html上有一个简单的页面:
<html>
<body>
<p>Javascript (dynamic data) test:</p>
<p class='jstest' id='yesnojs'>Hello</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById('yesnojs').innerHTML = 'GoodBye';
}
</script>
</body>
</html>
我希望你能帮我,谢谢。
PD:这是我在Python上尝试抓取页面的代码:
from selenium import webdriver
chrome_path=
"C:\\Users\\Antonio\\Downloads\\chromedriver_win32\\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("http://localhost/templates/scraping.html")
review = driver.find_elements_by_class_name("jstest")
for post in review:
print(post.text)
发布于 2018-05-12 00:46:51
Selenium不会附加到您现有的打开网页上。它会打开一个新的网页。如果您正在设计单元测试,则必须使用Selenium模拟单击。
或者,您是否正在考虑创建一个浏览器扩展来在此事件发生时执行抓取操作,Selenium不是用于此目的的工具。
https://stackoverflow.com/questions/50294963
复制相似问题