0

I'm first time to ask questions here and I'm new to Python.

I install the mechanize and BeautifulSoup to change some forms from a page.

Now, I use br.submit() to send the request , it doesn't work!

Is there any way to call the onclick function(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.

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?

趙偉丞
  • 51
  • 7

1 Answers1

1

mechanize cannot handle javascript:

Instead, you can automate a real browser via selenium. Example:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('myurl')

link = driver.find_element_by_link_text('search')
link.click()
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195