Last active
March 5, 2021 16:17
-
-
Save xyxc0673/15ffbf94b4e83556e3e46eb19aa7fd73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const cheerio = require("cheerio"); | |
const headers = { | |
Origin: "https://www.v2ex.com", | |
Referer: "https://www.v2ex.com/signin", | |
Host: "www.v2ex.com", | |
'Content-Type': 'application/x-www-form-urlencoded', | |
}; | |
const login = async () => { | |
const response = await axios.get("https://v2ex.com/signin"); | |
const $ = cheerio.load(response.data); | |
const inputList = $("input.sl"); | |
const params = { | |
username: "", | |
password: "", | |
captcha: "", | |
once: "", | |
next: "/", | |
}; | |
const keys = Object.keys(params); | |
inputList.each((i, input) => { | |
const key = keys[i]; | |
params[key] = $(input).attr("name") || ""; | |
}); | |
params.once = $("input[name=once]").attr("value") || ""; | |
const data = { | |
[params.username]: "123", | |
[params.password]: "233", | |
[params.captcha]: "4444", | |
once: params.once, | |
next: "/", | |
}; | |
const res = await axios.post("https://v2ex.com/signin", data, { | |
headers, | |
withCredentials: true, | |
}); | |
console.log("res", res.data) | |
}; | |
login(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment