Python机械化如何单击链接
我需要按下一个有以下代码的按钮:Python机械化如何单击链接,python,mechanize,Python,Mechanize,我需要按下一个有以下代码的按钮: "<a href="/follows?followed_id=101769" class="js-toggle-follow btn-social btn-follow data-method="post" data-remote="true" id="follow" rel="nofollow">" “但它不是一个按钮,它是一个链接,看起来像一个按钮。请尝试通过“id=”follow“进行查找。”“标准我认为,这两个答案将非常有用:但这是
"<a href="/follows?followed_id=101769" class="js-toggle-follow btn-social btn-follow data-method="post" data-remote="true" id="follow" rel="nofollow">"
“但它不是一个按钮,它是一个链接,看起来像一个按钮。请尝试通过“id=”follow“进行查找。”“标准我认为,这两个答案将非常有用:但这是代码包含在表单中而不是表单中,我无法访问链接。这是行不通的。有人能给我一个我该怎么做的示例代码吗?有很多关于提交表单的教程。
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!!!"