[英]How should I use this onclick(javascript) in Python
I'm first time to ask questions here and I'm new to Python. 我是第一次在这里问问题,而我是Python的新手。
I install the mechanize and BeautifulSoup to change some forms from a page. 我安装了机械化和BeautifulSoup来更改页面中的某些表格。
Now, I use br.submit()
to send the request , it doesn't work! 现在,我使用
br.submit()
发送请求,它不起作用!
Is there any way to call the onclick
function(javascript)? 有什么方法可以调用
onclick
函数(javascript)?
Here is the code about that button send data: 这是关于该按钮发送数据的代码:
<div class="go_btm w_a1">
<p class="gogo"><a href="#" onclick="javascript:checkdata(document.mainform);" onkeypress="checkdata(document.mainform);">search</a></p>
<p class="gogo"><a href="#" onclick="reset();" onkeypress="reset();">cancel</a></p>
<br class="CLEAR" />
</div>
UPDATE: 更新:
Thank you for support the Selenium this tool. 感谢您对Selenium这个工具的支持。
But I have another problem. 但是我还有另一个问题。 My code below:
我的代码如下:
for i in range(len(all_options)): arr.append(all_options[i])
count = 0 for option in arr: print("Value is: %s" % option.get_attribute("value")) if count > 1: option.click() string = u'search' link2 = browser.find_element_by_link_text(string.encode('utf8')) response = link2.click() browser.back() count = count + 1
After I back to the same page,it answer me: 回到同一页后,它回答我:
Traceback (most recent call last): File "C:\\Users\\pc2\\Desktop\\TEST.py", line 44, in <module> print("Value is: %s" % option.get_attribute("value")) File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py", line 93, in get_attribute resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name}) File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\webelement.py", line 385, in _execute return self._parent.execute(command, params) File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\webdriver.py", line 173, in execute self.error_handler.check_response(response) File "C:\\Python27\\lib\\site-packages\\selenium\\webdriver\\remote\\errorhandler.py", line 166, in check_response raise exception_class(message, screen, stacktrace) StaleElementReferenceException: Message: stale element reference: element is not attached to the page document (Session info: chrome=40.0.2214.111) (Driver info: chromedriver=2.9.248315,platform=Windows NT 6.1 SP1 x86_64)
I can only click the select once. 我只能单击一次选择。
Is that talk me my option in the array disappear? 那是我在说我在阵列中的选择消失了吗?
How should I keep the variable(option) let next loop to click? 我应该如何让变量(选项)让next循环单击?
mechanize
cannot handle javascript: mechanize
无法处理javascript:
Instead, you can automate a real browser via selenium
. 相反,您可以通过
selenium
自动化真正的浏览器 。 Example: 例:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('myurl')
link = driver.find_element_by_link_text('search')
link.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.