首页 > 代码库 > pythn抓取网页小例子

pythn抓取网页小例子

import urllib.requestimport refrom tkinter import *win = Tk()win.geometry(500x300+400+300)t = Text(win)t.pack()url = http://stock.sohu.com/news/html = urllib.request.urlopen(url).read()html = html.decode(GBK)pattern = re.compile("<a test=a href=http://www.mamicode.com/‘http://stock.sohu.com/(.*?)/(.*?).shtml‘ target=‘_blank‘>(.*?)",re.S)items = re.findall(pattern,html)for item in items:    t.insert(END,item[2])    t.insert(END,\n)    

 

pythn抓取网页小例子