I am trying to implement a small program that can press the UPVOTE button on reddit messages.
I can successfully log in and go to the message url. But I can’t find a solution that can allow me to press the UP VOTE button of the message that I really want to click.
Is there a way to mechanize clicking the up button? The html upvote structure is below
<div class="midcol unvoted"><div tabindex="0" aria-label="upvote" role="button" data-event-action="upvote" class="arrow up login-required archived access-required"></div><div class="score dislikes">7</div><div class="score unvoted">8</div><div class="score likes">9</div><div tabindex="0" aria-label="downvote" role="button" data-event-action="downvote" class="arrow down login-required archived access-required"></div></div>
Run codeHide resultbr = mechanize.Browser()
br.addheaders = generate_user_agent()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.addheaders=[('user-agent','Mozilla-Firefox')]
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.open('http://www.reddit.com') # Select the second (index one) form
br.select_form(nr=1) # User credentials
br.form['user'] = 'user'
br.form['passwd'] = 'pass'
Run codeHide result
source
share