0

I need to press a button which has this code:

"<a href="/follows?followed_id=101769" class="js-toggle-follow btn-social btn-follow     data-method="post" data-remote="true" id="follow" rel="nofollow">"

The button doesn't have "name" and I don't know how to find it using "id" and then click.

I'm using Python with Mechanize. In the coment pulsar enlace i want to click the button and then forwards to next user.

This is the script:

import mechanize
import cookielib
import sys
import os

url= "http://web.com/users/sign_in"

br = mechanize.Browser()
cj = cookielib.LWPCookieJar()

br.set_cookiejar(cj)
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; es-VE;  rv:1.9.0.1)Gecko/2008071615 Debian/6.0 Firefox/9')]

r=br.open(url)

br.select_form(nr=2)

br.form['user[login]'] = '@hotmail.com'
br.form['user[password]'] = '123123'
os.system('clear')
try:    
print "Loggin....."
br.submit()
except:
print "Logued failed..."
sys.exit()
print "Logued Succesfully!!!"

i=0
ok=0
url77="http://web.com"
enlaceexiste = False
usuarioexiste = False
while i < 100000:

    try: 
    br.open(url77+"/users/"+str(i))
    print "Accessing "+url77+"/users/"+str(i)
    usuarioexiste = True
    except:
    print "User "+str(i)+" failed..."
    usuarioexiste = False
    enlaceexiste = False
    if usuarioexiste:
    try:
        enlace = br.find_link(text='Seguir')
        enlaceexiste = True
            print enlace

    except:
        print "No follow button!"
        enlaceexiste = False

    if enlaceexiste:
    try:
        #pulsar enlace      
        ok+=1
        print "\tTotal users followed and challenged: "+str(ok)
    except:
        print "\tCant follow user "+str(i)
        i+=1
    enlaceexiste = False
   i+=1
print "All users finished!!!"
Xenomorfo77
  • 1
  • 1
  • 2
  • But it's not a button, it's a link, looking like a button. Try to look up via " id="follow" " criteria – mega.venik Feb 10 '14 at 20:43
  • 1
    I think, these two answers would be very helpful: http://stackoverflow.com/questions/10495313/mechanize-select-form-using-id http://stackoverflow.com/questions/7673905/python-mechanize-select-form-formnotfounderror – mega.venik Feb 10 '14 at 20:49
  • But that's code is included in a
    not in a form and i cant go to link. It dont works.
    – Xenomorfo77 Feb 10 '14 at 20:56
  • Can someone put a example code of what should i do? – Xenomorfo77 Feb 11 '14 at 16:32
  • There are many tutorials out there for submitting forms. http://www.pythonforbeginners.com/cheatsheet/python-mechanize-cheat-sheet – User Feb 14 '14 at 01:48

0 Answers0