Ben*_*Ben 1 selenium selenium-webdriver
我的程序无法使用 Selenium 从网页获取现有类。我的 WebDriver.execute_script 函数似乎不起作用。
import urllib
from selenium import webdriver
#Path to the chromedriver is definitely working fine.
path_to_chromedriver = 'C:\Users\Ben\Desktop\Coding\FreeFoodFinder\chromedriver.exe'
browser = webdriver.Chrome(executable_path = path_to_chromedriver)
url = 'http://www.maidservicetexas.com/'
browser.implicitly_wait(30)
browser.get(url)
content = browser.execute_script("document.getElementsByClassName('content')");
#Just printing the first character of the returned content's toString for now. Don't want the whole thing yet.
#Only ever prints 'N', the first letter of 'None'...so obviously it isn't finding the jsgenerated content even after waiting.
print content
Run Code Online (Sandbox Code Playgroud)
我的程序返回“无”,这告诉我 javascript 函数没有返回值/正在执行。Chrome 的网络开发工具告诉我“内容”当然是一个有效的类名。该网页甚至不是动态生成的(我的最终目标是抓取动态内容,这就是为什么我让我的 WebDriver 在运行脚本之前等待 30 秒。)
返回值:
content = browser.execute_script("return document.getElementsByClassName('content');");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2172 次 |
| 最近记录: |