Golang、python中登入開源中國,並發表部落格。

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

GO、python用不了十幾分鐘可以做出來,易語言的話,可能幾分鐘完事,國產易語言感覺快捷啊。

 

 

type loginSave struct {   returnCk []*http.Cookie}type oschina interface {   login(user string, pass string) string   save(title string, content string) string}func main() {   user := "xxxxxx@qq.com"//帳號   pass := "XXXXXXXXXX"//密碼   user = strings.Replace(user, "@", "%40", 1)   pass = (shaCryto(pass))   lo := loginSave{[]*http.Cookie{}}   lo.login(user, pass)   lo.save("testAll", "Look At me")}func shaCryto(src string) string {   h := sha1.New()   h.Write([]byte(src))   return hex.EncodeToString(h.Sum(nil))}func (lo *loginSave) login(user, pass string) string {   client := &http.Client{}   req, err := http.NewRequest("POST", "https://www.oschina.net/action/user/hash_login", strings.NewReader("email="+user+"&pwd="+pass+"&verifyCode=&save_login=1"))   if err != nil {      // handle error   }   req.Header.Set("Content-Type", "application/x-www-form-urlencoded")   resp, err := client.Do(req)   defer resp.Body.Close()   body, err := ioutil.ReadAll(resp.Body)   if err != nil {      // handle error   }   lo.returnCk = resp.Cookies()   fmt.Println(string(body))   fmt.Println("==================")   return "1"}func (sa *loginSave) save(title string, content string) string {   client := &http.Client{}   fmt.Println(sa.returnCk)   req, err := http.NewRequest("POST", "https://my.oschina.net/action/blog/save", strings.NewReader("draft=590308&user_code=xOWIzsSFMaowkBF0oldQJNuJcH2vDgUfhCGC55PY&id=&catalog=286094&title="+title+"&content_type=4&tags=&classification=428640&type=1&origin_url=&privacy=1&deny_comment=1&as_top=0&isRecommend=on&abstracts=&content=%3Cp%3E"+content+"%3C%2Fp%3E%0A&temp=1490495330601"))   if err != nil {      // handle error   }   fmt.Println(sa.returnCk)   req.Header.Set("Content-Type", "application/x-www-form-urlencoded")   for _, i := range sa.returnCk {      req.AddCookie(i)   }   resp, err := client.Do(req)   defer resp.Body.Close()   body, err := ioutil.ReadAll(resp.Body)   if err != nil {      // handle error   }   fmt.Println(resp.Cookies())   fmt.Println(string(body))   return "1"}

 

python的話,沒有寫了,因為我做這種POST程式做得想吐了,估計做了幾百個了。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.