1 # -*- coding: utf-8 -*- 2 import urllib 3 from bs4 import BeautifulSoup 4 from time import time 5 from time import ctime 6 def get_last_info(): 7 url='http://ggjd.cnstock.com/gglist/search/ggkx/0' 8 9 html=urllib.urlopen(url) 10 11 bsobj2=BeautifulSoup(html,"lxml") 12 13 alltext=bsobj2.body.findAll("ul",class_="new-list") 14 #print alltext[1].get_text()#ok,需要的信息在第二个new-list 15 l_2=len(alltext) 16 17 file_open=open(r'C:UsersAdministratorDesktopsecuritiessecurities_info1.txt','w') 18 19 t1= alltext[1].get_text() 20 21 t1=t1.encode("utf-8") 22 t1="<获取信息时间>:%s "%ctime()+url+' '+"中国证券网->上市公司专区->信息披露与公告解读->公告快讯:"+t1 23 24 print t1 25 file_open.write(t1) 26 file_open.close() 27 if __name__=="__main__": 28 get_last_info()