跳至主要内容

博文

目前显示的是标签为“web”的博文

go handle upload multiple File

package main import ( f "fmt" "html/template" "io" "net/http" "os" ) func main() { http.HandleFunc("/", home) http.HandleFunc("/uploadfiles", uploadfiles) http.ListenAndServe(":8080", nil) } func home(w http.ResponseWriter, r *http.Request) { t, _ := template.ParseFiles("index.html") t.Execute(w, nil) } func uploadfiles(w http.ResponseWriter, r *http.Request) { r.ParseMultipartForm(1 << 30) fhs := r.MultipartForm.File["uploadFile"] for _, v := range fhs { file, err := v.Open() if err != nil { f.Println(err) return } mf, err := os.OpenFile("./"+v.Filename, os.O_WRONLY|os.O_CREATE, 0666) if err != nil { f.Println(err) return } defer mf.Close() io.Copy(mf, file) } f.Fprintf(w, "ok") } //index.html <!DOCTYPE html> <html> <head> <title>upload</title...

python 2.7 web crawler

#coding=utf-8 #python 2.x import re import urllib def getHtml(url): page=urllib.urlopen(url) html=page.read() return html html=getHtml("http://www.jianshu.com") reg=r'<h4 class="title"><a target="_blank" href="(.*?)">(.*?)</a>' hotre=re.compile(reg) artlist=re.findall(hotre,html) for article in artlist: for com in article: print com