Open spacemud opened 7 years ago
The problem is in the GetToken function which scrap the csrf token from the login page, I am no expert in go but after checking the source code, I found that you are still using the baseUrl as your target, which is wrong because the login page is under baseUrl/login, then there is the token, I don't know why using the gjuery something package, and because I didn't understand what you are doing by "find(login-button[token]) line I rewrote the function using
body, err := ioutil.ReadAll(resp.Body)
then convert the bytes array to a string like
bodyString := string(body[:])
then using regex to get the token
tokenValue := regexp.MustCompile(`[0-9a-zA-Z]{40,50}`)
token := tokenValue.FindString(bodyString)
And that's it
That seems to fix the login issue, yes. Unfortunately I think Laracasts has updated the site since this was released, which breaks other parts of the script that also depend on scraping.
I get an error message when attempting to login:
2017/05/02 20:48:47 https://laracasts.com/sessions returned wrong status code: 500, expected 200
My details are correct.