ImportRequestsImportRe#Embarrassing encyclopedia ReptileclassQSBK:#Initialize method, define some variables def __init__(self): Self.headers={ "user-agent":"mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/61.0.3163.79 safari/537.36" } #The variable that holds the satin, each element is a piece of each pageself.stories=[] #variables to keep the program runningSelf.enable =FalsedefGetPage (self,page):Try: URL='http://www.qiushibaike.com/hot/page/'+Str (page)Print(URL) Response= Requests.get (url,headers=self.headers) html_content= Response.content.decode ('UTF-8') #print (html_content) #regex=re.compile (' <div class= ' article block untagged mb15\s\s+ "id=" \s+ ">.*?</div>")Regex = Re.compile ('', Re. S)#regex = re.compile (' Regex_content =Re.findall (Regex, html_content)Print(regex_content) forIinchregex_content:self.stories.append (I[0].replace ('\ n',"'), I[1].replace ('\ n',"')) returnself.storiesexceptException as E:Print('Exception:%s'%e) JS=QSBK () forIinchRange (100): Lists=js.getpage (i)Print('============================================ First'+str (i) +'page =============================================') Print(lists)
If it doesn't work out, it's embarrassing and changing the rules.
Python a small program that captures embarrassing jokes