获取内涵段子的python 和 显示图片

3/8/2017来源:ASP.NET技巧人气:1351

# -*- coding: utf-8 -*- import urllib2,os,cookielib import sys type = sys.getfilesystemencoding() i=0 cookie=cookielib.CookieJar() opner=urllib2.build_opener(urllib2.HTTPCookiePRocessor(cookie)) while 1==1:   response=opner.open(urllib2.Request('http://neihanshequ.com/'))   html = response.read()   while html.find("data-text=\"")!=-1:     html=html[html.find("data-text=\"")+len("data-text=\""):]     text=html[0:html.find("\"")]     joke=str(i)+'.'+text+'\n'     i+=1     print joke.decode('utf-8').encode(type)     os.system("pause")   html=''   i=0

import wx

class  Frame(wx.Frame):     max_width = 400     max_height = 600     def __init__(self,app):         wx.Frame.__init__(self,None,-1,"ShowPic",size=(400,600))         self.bmoved=False         self.app=app         self.bmp = wx.StaticBitmap(self, 0, wx.NullBitmap, (0,0), (400,400))         self.Hide()          def ShowImage(self,path):         image=wx.Image(path,wx.BITMAP_TYPE_ANY)         bmp=image.ConvertToBitmap()         size=self.GetSize(bmp)         print size         self.SetSize(size)         bmp=image.Scale(size[0], size[1]).ConvertToBitmap()         self.bmp.SetSize(size)         self.bmp.SetBitmap(bmp)         self.Show()     def GetSize(self, bmp):         width = bmp.GetWidth()         height = bmp.GetHeight()         if width>self.max_width:             height = height*self.max_width/width             width = self.max_width         if height>self.max_height:             width = width*self.max_height/height             height = self.max_height         size = width, height         return size          class APP(wx.App):     def __init__(self, redirect=False):         wx.App.__init__(self, redirect)     def OnInit(self):         self.frame=Frame(self)         self.ShowImage()         self.frame.Show()         return True     def ShowImage(self):         self.frame.ShowImage("C:\\Users\\Administrator\\Desktop\\1.jpg")     def Close(self):         self.frame.Close() def main():     app=APP()     app.MainLoop() if __name__ == '__main__':     main()