Recently, the reptile is more interested in the study of a bit.
Recommend a Python crawler blog http://blog.csdn.net/pleasecallmewhy/article/details/9305229 Click to open the link. After the blogger's blog learned, he wrote a crawl Bupt library rankings of the demo.
#!/usr/bin/env python#-*-coding:utf-8-*-#---------------------------------------# Program: Bupt Library Crawler-Leaderboard # version: 0.1# Zhan gxuan# Date: 2015-04-15# language: Python 2.7# action: Enter account number and password # function: #---------------------------------------' a test module ' __aut hor__ = ' Zhangxuan ' import urllibimport urllib2import cookielibimport Recookie = cookielib. Cookiejar () opener = Urllib2.build_opener (urllib2. Httpcookieprocessor (cookie)) opener.addheaders = [(' User-agent ', ' mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:37.0) gecko/20100101 firefox/37.0 ')]urllib2.install_opener (opener) #需要POST的数据 #postdata=urllib.urlencode ({' Login_type ': ' E_card ', ' barcode ': ' 2014110590 ', ' Password ': ' 1105090 ', ' _ ': '} ' #自定义一个请求 #req = urllib2. Request (url = ' http://10.106.0.217:8080/opac_two/reader/infoList.jsp ', data = postdata) #访问该链接 # #result = Opener.open (req) result = Urllib2.urlopen (req) #打印返回的内容 #print result.read (). Decode (' GBK '). Encode (' Utf-8 ') #打印cookie的值for item in Cookie:print ' cookie:name = ' +item.name priNT ' Cookie:value = ' +item.valueresult = Opener.open (' http://10.106.0.217:8080/opac_two/top/top.jsp ') print U ""------ ------------------------------------------------------------------------"" "MyPage = Result.read () myitems = Re.findall (' <div class= '. *? >.*?<a href= ". *?". *?target= "_blank" > (. *?) </a>.*?</div>.*?<div class= ". *?" > (. *?) </div> ', Mypage,re. S) for item in Myitems:print item[0].decode (' GBK '). Encode (' Utf-8 ') print item[1].decode (' GBK '). Encode (' Utf-8 ')
The code is basically modeled after that blog, but the specific analysis of the concrete part of the changes, we can go to see his detailed explanation.
Regular expressions fetch data because they do not have a lot of skill.
The number of times the title was taken out and the loan retrieved.
The final:
[Python] web crawler: Bupt Library Rankings