這裏主要是給出界面,讓用戶能夠選擇保存的路徑,還有網絡地址可選,使用wxPython庫編寫網絡
#encoding:UTF-8import wximport osimport crawlFirstclass SelectPath(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,None,-1,u"選擇保存路徑(做者:董繼超 版權全部)",size=(500,300),style=wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN) panel=wx.Panel(self,-1) button1=wx.Button(panel,label=u"開始",pos=(20,220),size=(60,30)) button2=wx.Button(panel,label=u"關閉",pos=(100,220),size=(60,30)) button3=wx.Button(panel,label=u"選擇文件夾",pos=(380,77),size=(100,30)) sList=["http://www.2cto.com/meinv/rhmeinv/","http://www.2cto.com/meinv/sexmv"] wx.StaticText(panel,-1,u"選擇一個網址",(20,25)) self.combo= wx.ComboBox(panel,-1,"http://www.2cto.com/meinv/rhmeinv/",(100,22),choices=sList,style=0) self.input_text = wx.TextCtrl(panel, -1, u"",pos=(20,80), size=(350, 25)) self.Bind(wx.EVT_BUTTON,self.OnStart,button1) self.Bind(wx.EVT_BUTTON,self.OnCloseMe,button2) self.Bind(wx.EVT_BUTTON,self.OnSelPath,button3) self.Bind(wx.EVT_CLOSE,self.OnCloseWindow) def OnSelPath(self,event): dialog=wx.DirDialog(None,u"選擇圖片保存的目錄",style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON) if dialog.ShowModal()==wx.ID_OK: self.input_text.SetValue(dialog.GetPath()) def OnStart(self,event): sPath=self.input_text.Value.strip(" ") if sPath =="": wx.MessageBox(u'請選擇保存路徑',u'提示',wx.OK|wx.ICON_INFORMATION) return elif not os.path.exists(sPath): wx.MessageBox(u'所選路徑不存在',u'提示',wx.OK|wx.ICON_INFORMATION) return else: print self.combo.Value crawlFirst.GetUrlContent(self.combo.Value,sPath) def OnCloseMe(self,event): self.Close(True) def OnCloseWindow(self,event): self.Destroy()if __name__=='__main__': app=wx.PySimpleApp() frame=SelectPath(parent=None,id=-1) frame.Show() app.MainLoop()