In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how python climbs each classified book list of Douban". In daily operation, I believe many people have doubts about how to climb each classified book list of Douban by python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to climb each classified book list of python"! Next, please follow the editor to study!
Code display:
Pachon2.5.py #-coding: utf-8-import urllibimport urllib2import reimport sys
Reload (sys)
Sys.setdefaultencoding ('utf-8')
Class book: # similar def init of Douban Books (self, types) Page): self.baseUrl = 'http://www.douban.com/tag/' self.types = types self.filename =' doubanbook.txt' self.page = pagedef getContents (self): # crawl source code try: # if self.page = = 0: url = self.baseUrl + self.types +'/ book' # else: # url = self.baseUrl + Self.types +'/ book?start=' + str (self.page) user_agent = 'Mozilla/5.0 (Windows NT 6.3) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36' headers = {'User-Agent': user_agent} request = urllib2.Request (url,headers = headers) response = urllib2.urlopen (request) content = response.read () # .decode (' utf-8') pattern = re.compile ('(. *?). Re.S) items = re.findall (pattern,content) return items except urllib2.URLError, e: if hasattr (e, "reason"): print u "Douban link error Cause of error ", e.reason return None
Def writetext (self, items): # write txt for item in items: print item [0], item [1] files = open (self.filename,'a') files.write (item [0]) files.write (item [1]) files.write ('\ n') files.close ()
Def strat (self): # Boot function self.writetext (self.getContents ()) print u "is normal. There will be one more in the same folder as this script. There are some books in the doubanbook.txt file. If you put this script on the desktop, the file will appear on the desktop "" print u "end type'O', contact the author and enter'A'" end = raw_input ('>') if end = 'A': print u "QQ Mail: 1021644861@qq.com" raw_input (' >') else: print "over" here. The study on "how python climbs each classified book list of Douban" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.