Crawling forms with hidden inputs

agolangf · · 429 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Currently I&#39;m trying to crawl my own grades from my school their website. </p> <p>I would like some help on the login part of system. Because my school uses some sort of form protection I send a get request first. To fetch the needed hidden input data.</p> <p>after that i&#39;m building an URL with the form data in it. This is how my school handles the submitted form.</p> <p>But when I&#39;m using golang everytime I submit the form I get the response from the web server saying that the form is already submitted.</p> <p>This makes no sense to me because I didn&#39;t send any other request besides the get request to get the Token from the hidden input.</p> <p>In postman rest client it works (getting the token &amp; building url and submitting with a POST)</p> <p>Someone has any idea, I&#39;m kinda stuck on this for a time now</p> <p>code:</p> <p>package main</p> <pre><code>import ( &#34;fmt&#34; &#34;io/ioutil&#34; &#34;log&#34; &#34;net/http&#34; &#34;regexp&#34; &#34;strings&#34; ) type client struct { http.Client } var ( postLoginURL = &#34;?submit=inloggen&amp;_eventId=submit&amp;username=%s&amp;password=%s&amp;credentialsType=ldap&amp;lt=%s&#34; loginURL = &#34;https://login.hro.nl/v1/login&#34; logoutURL = &#34;https://login.hro.nl/v1/logout&#34; ) func insertCredentials(username, password, ltkey string) string { return fmt.Sprintf(postLoginURL, username, password, ltkey) } func getToken() (key string) { //Request client := &amp;http.Client{} req, err := http.NewRequest(&#34;GET&#34;, loginURL, nil) if err != nil { log.Fatalln(err) } req.Header.Set(&#34;User-Agent&#34;, &#34;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36&#34;) resp, err := client.Do(req) if err != nil { //If there is no request possible, terminate the program panic(&#34;Cannot fetch the Token, check server status!&#34;) } //Read content from the body content, err := ioutil.ReadAll(resp.Body) defer resp.Body.Close() //Regex to match the value from the hidden input (Example:_s6014490C-B11F-9828-1574-467F8E575E72_c983D179C-1117-2DA6-D5FD-96331CD3CD38) match := regexp.MustCompile(&#34;_s.{74}&#34;) key = match.FindString(string(content)) if err != nil { return &#34;&#34; } return } func (c *client) login(uri string) { fmt.Println(loginURL + uri) params := strings.NewReader(uri) req, err := c.Post(loginURL, &#34;application/x-www-form-urlencoded&#34;, params) data, err := ioutil.ReadAll(req.Body) fmt.Println(req) fmt.Println(isValid(data)) fmt.Println(string(data)) defer req.Body.Close() // error handle if err != nil { fmt.Printf(&#34;error = %s \n&#34;, err) } } func isValid(body []byte) bool { r := regexp.MustCompile(&#34;has been submitted already&#34;) if r.Match(body) { return false } return true } func main() { cl := &amp;client{} cl.login(insertCredentials(&#34;XXX&#34;, &#34;XXXX&#34;, getToken())) } </code></pre> <hr/>**评论:**<br/><br/>Snavelzalf: <pre><p>Even when getting the Token from the browser and then using it as parameter it says cannot be resubmitted!</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

429 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传