python怎样避免验证码
写个程序登录51job读数据,发现总是让输入图片里的验证码,而我用浏览器时则没有这个提示,怎样能像浏览器时那样,绕过输入验证码这个步骤呢?
代码:
loginUrl = 'http://my.51job.com/my/My_SignIn.php'
loginform = urllib2.urlopen(loginUrl).read()
bs = BeautifulSoup(loginform)
url = bs.find('div', 'login_box').find('form')['action']
myCookie = urllib2.HTTPCookieProcessor(cookielib.CookieJar());
opener = urllib2.build_opener(myCookie)
post_data = {
'username':'user',
'userpwd':'pwd',
'url':'',
'x':'45',
'y':'17'
}
req = urllib2.Request(url, urllib.urlencode(post_data))
req.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6')
#req.add_header('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
#req.add_header('Accept-Encoding','gzip,deflate')
html_src = opener.open(req).read()
[解决办法]