在python中单击带有mechanize的NON FORM按钮

时间:2016-05-15 14:49:17

标签: python mechanize

我正在尝试实现一个小程序,可以点击reddit帖子上的UPVOTE按钮。

我能够成功登录并转到帖子的网址。 但我无法找到一个解决方案,可以让我点击我真正想要点击的帖子的UP VOTE按钮。

是否有机械化点击upvote按钮? html中upvote的结构如下所示



<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>
&#13;
&#13;
&#13;

&#13;
&#13;
br = 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'
&#13;
&#13;
&#13;

0 个答案:

没有答案