1
驗證碼是隨機生成的。我得到驗證碼的鏈接並下載它。之後,我使用此驗證碼和標題正確設置標題來抓取網站。但是,錯誤顯示驗證碼錯誤!我不知道如何解決這個問題。看起來,當我得到一個驗證碼時,它被改變了。有人能幫我嗎?任何幫助將不勝感激。Python網絡蜘蛛:如何解決captcha?
我的腳本:
#coding=utf-8
import urllib
import urllib.request as urllib2
import sys
import http.cookiejar as cookielib
import time
import os
time=time.time()
cookiejar=cookielib.CookieJar()
urlopener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
urllib2.install_opener(urlopener)
urlopener.addheaders.append(('Referer', 'http://www.jsgsj.gov.cn:58888/mini/netweb/SMLibrary.jsp'))
urlopener.addheaders.append(('Accept-Language', 'zh-CN'))
urlopener.addheaders.append(('Host', 'www.jsgsj.gov.cn:58888'))
urlopener.addheaders.append(('User-Agent', 'Mozilla/5.0 (compatible; MISE 9.0; Windows NT 6.1); Trident/5.0'))
urlopener.addheaders.append(('Connection', 'Keep-Alive'))
imgurl='http://www.jsgsj.gov.cn:58888/mini/netWebServlet.json?randImg=true&tmp='+str(time)
outfile=open(r'code.jpg', 'wb')
response=urllib2.Request(imgurl)
html=urlopener.open(response)
outfile.write(html.read())
outfile.close()
authcode=raw_input('enter the code:')
url_company='http://www.jsgsj.gov.cn:58888/mini/netWebServlet.json?codeCheck=true'
data={'corpName':'蘇州','yzm':authcode}
html=urlopener.open(urllib2.Request(url_company,urllib.urlencode(data)))
page=(html.read())
print ("html:",yzm, page)
也許,你應該試試這個:https://pypi.python.org/pypi/captcha-solver/0.0.3 –
好問題! – Veltro