分享
Golang、python中登录开源中国,并发表博客。
大洋的顶端 · · 1999 次点击 · · 开始浏览这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。
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程序做得想吐了,估计做了几百个了。
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信1999 次点击
上一篇:go语言实现7大排序算法
下一篇:golang中开启gctrace
添加一条新回复
(您需要 后才能回复 没有账号 ?)
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
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程序做得想吐了,估计做了几百个了。