# coding:utf-8from urllib.request Import urlretrieveimport threadingimport requestsfrom BS4 Import Beautifulsoupfrom DateTime import datetimeimport pymysqlimport randomimport jsonimport timenumber=0def getarticel (): max_ Time = 1519404642 data = Requests.get ("Http://www.neihanshequ.com/joke/?is_json=1&app_name=neihanshequ_web &max_time= "+ str (max_time)) soup = BeautifulSoup (data.text, ' html5lib ') #print (Soup.select_one (' body ') . Get_text ()) Global number jsondata=json.loads (str (soup.select_one (' body '). Get_text ())) Articlelist =jsondata[' data ' [' data '] f = open ("Article.txt", ' a ', encoding= ' Utf-8 ') for item in Articlelist: Number+=1 #print (number) F.write (item[' group ' [' Content ']+ ' \n\n\n ') print (number) F.close ( # Print (count) # Print (item) If __name__ = = ' __main__ ': for I in range (1,10): print (i) # Getarticel () #time. Sleep (1)
Python crawl connotation satin article