Python a small program that captures embarrassing jokes

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.