[英]Cannot identify element in splinter browser
我有以下HTML片段
<input type="text" name="fldLoginUserId" maxlength="15" size="10" onkeypress="return fSubmit(event);" value="" class="input_password">
這是較大的HTML的一部分。 我可以使用Chrome-Inspect看到此元素。 但是,當我嘗試類似
myurl = 'xxx' # I am hiding xxx as I dont want to disclose the site here
from splinter import Browser
browser = Browser('chrome', **executable_path)
browser.visit(myurl)
customerId = browser.find_by_name('fldLoginUserId')
這會將customerId
作為空列表返回。
有人可以指出我犯的任何錯誤嗎?
這是我第一次在這里使用Splinter和python。 您的代碼似乎可以正常工作:
#!/usr/bin/python
from splinter import Browser
browser = Browser('chrome')
browser.visit('http://migueleonardortiz.com.ar')
customerId = browser.find_by_name('generator')
for objectx in customerId :
print objectx._element.get_attribute('content')
輸出:
mortiz@florida:~/Documents/projects/python/splinter$ python web_browser_splinter.py
Divi v.2.5.6
WordPress 4.9.6
當我要求HTML中不存在的值時,輸出為空列表:
mortiz@florida:~/Documents/projects/python/splinter$ python web_browser_splinter.py
[]
我已經將您的財產跟蹤到您可能正在使用的站點。 HTML正在用Javascript渲染:
document.write('<input type="text" name="fldLoginUserId" maxlength="15" size="13" autocomplete="off" onkeypress = "return fSubmit(event);" value="" oncopy="return false" ondrag="return false" ondrop="return false" onpaste="return false" />')
並且盡管該屬性存在於HTML檢查中,但無法以與我提供的示例相同的方式進行檢索。
因為它是用Javascript渲染的,所以我想這與它和DOM加載順序有關。
只是一個猜測,也許是一個很好的起點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.