Python Forum
Click on button with python mechanize - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Click on button with python mechanize (/thread-7300.html)



Click on button with python mechanize - torlkius - Jan-03-2018

Hello,

I would like to click a button using mechanize but I can't find the right code.

Until then, I had succeeded because I was going through the mobile version of twitter and I didn't have to deal with javascript.

Apparently for this page it is not possible. I would like to avoid using selenium, is it possible to do a
br.submit()
on the blue button below?

[Image: zWNGswn.png]

Thank you !


RE: Click on button with python mechanize - metulburr - Jan-03-2018

try this
br.submit(id='allow')
if there is javascript in there, then you cannot do it with mechanize. You will need selenium.


RE: Click on button with python mechanize - torlkius - Jan-03-2018

Thank you very much for your answer.

I got this error:

Quote:Traceback (most recent call last):
File "test.Acc0unt_Cr3at0r.2.py", line 165, in <module>
br.submit(id='allow')
File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 541, in submit
return self.open(self.click(*args, **kwds))
File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 530, in click
request = self.form.click(*args, **kwds)
AttributeError: 'NoneType' object has no attribute 'click'



RE: Click on button with python mechanize - metulburr - Jan-03-2018

A couple ways to test if javascript is the issue.

1) turn javascript off on your browser and see if the button is selectable or even viewable. If not then javascript is providing it. I dont have a twitter account so i cannot test it.

2) See if BeautifulSoup can see the button. If it cannot then most likely it is javascript.

I would check that first. If javascript is the problem, then your are shit out of luck and must use selenium.