我有两个文件,一个用户名列表和一个密码列表。我需要编写一个程序来检查每个用户名和密码列表。然后我需要去一个网站,看看它是否登录了。我不太确定如何进行比较,以及如何模拟程序登录网站输入信息。你能帮我解决这个问题吗?这是一个家庭作业的问题。
发布于 2011-03-04 09:47:39
无论您选择使用哪种语言来实现这一点,基本思想都是以编程方式模拟登录。这可以通过手动登录并查看HTTP标头,然后通过编程发送“伪造的”标头,更改用户/密码字段来完成。
大多数登录都会使用POST,创建POST并不是很简单。如果允许使用外部库,可以尝试使用cURL。只需设置适当的标头并查看响应,即可检查您的尝试是否成功。如果没有,请使用新的组合重试。
在伪代码中:
bool simulate_login(user, password) :
request = new request(url)
request.set_method('POST')
request.set_header('name', user)
request.set_header('pass', password)
response = request.fetch_reponse()
return response.contains("Login successful")
success = []
foreach user:
foreach password:
if (simulate_login(user, password)):
success.append((user, password))
break发布于 2011-03-04 09:54:21
如果你想使用java,你可以尝试使用HtmlUnit (参见:http://htmlunit.sourceforge.net/gettingStarted.html),或者如果你被允许,你可以使用http://www.gebish.org/
以下是入门指南中与您的案例相关的示例:
public void login() throws Exception {
final WebClient webClient = new WebClient();
// Get the first page
final HtmlPage page1 = webClient.getPage("http://some_url");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");
final HtmlSubmitInput button = form.getInputByName("submitbutton");
final HtmlTextInput textField = form.getInputByName("userid");
// Change the value of the text field
textField.setValueAttribute("username");
// Do similar for password and that's all
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();
webClient.closeAllWindows();
}发布于 2019-04-02 22:37:27
如果你想使用java,你可以尝试使用HtmlUnit (参见:http://htmlunit.sourceforge.net/gettingStarted.html),或者如果你被允许,你可以使用http://www.gebish.org/
以下是入门指南中与您的案例相关的示例:
public void login()抛出异常{ final WebClient webClient = new WebClient();
// Get the first page
final HtmlPage page1 = webClient.getPage("http://some_url");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");
final HtmlSubmitInput button = form.getInputByName("submitbutton");
final HtmlTextInput textField = form.getInputByName("userid");
// Change the value of the text field
textField.setValueAttribute("username");
// Do similar for password and that's all
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();https://stackoverflow.com/questions/5188734
复制相似问题