使用 chrome 扩展程序登录网站并从中获取数据 [英] Login to website with chrome extension and get data from it

查看:56
本文介绍了使用 chrome 扩展程序登录网站并从中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Chrome/Chromium 扩展程序,它将从学校系统读取学校成绩和成绩.问题是该站点不记得登录的用户.因此,我不能使用 AJAX.

I am developing a Chrome/Chromium extension that will be reading school grades from the school system with grades. Problem is that site doesn't remember logged user. Because of this, I cannot use AJAX.

仅当我在其他选项卡上登录到该页面时.但我想在后台自动登录该页面.解决方案可能是 iframe 标签,但 Chrome/Chromium 不允许我阅读和操作 iframe 内容.是否有任何解决方案如何以登录用户的身份在页面中进行操作?谢谢

Only if I'm logged to that page on other tabs. But I want to login to that page in the background and automatically. The solution may be maybe iframe tag, but Chrome/Chromium don't allow me to read and manipulate with iframe content. Is there any solution how to manipulate in the page as the logged user? Thank you

推荐答案

您可以模拟从后台页面通过 javascript 提交的表单.首先,您需要仔细检查通过登录表单发送了哪些数据以及发送到哪个 URL(表单可以在发送之前使用 javascript 进行更改,因此您需要知道实际发送的是什么,而不仅仅是 <form>元素).您可以使用 Chrome 的控制台来处理简单的事情,如果还不够,那么还有 用于 Firefox 的篡改数据插件,对于核心流量检查,您可以使用 Wireshark 分析器.

You can emulate form submit through javascript from a background page. First you need to carefully inspect what data is sent through the login form and to which URL (form could be altered with javascript before sending so you need to know what actually is sent, not just what's in <form> element). You can use Chrome's console for simple stuff, if it is not enough then there is Tamper Data plugin for Firefox, and for hardcore traffic inspection you can use Wireshark analyzer.

然后在后台页面中(我这里用的是jQuery):

Then in a background page (I am using jQuery here):

$.ajax({
    url: "https://login_form.html",
    type: "GET",
    dataType: "html",
    success: function() {
        $.ajax({
            url: "https://login_form_submits_to.html",
            type: "POST",
            data: {
                    "username": "username",
                    "password": "password",
                    "extra_field": "value"
            },
            dataType: "html",
            success: function(data) {
                   //now you can parse your report screen
            }
        });
    }
});

好在 Chrome 会保留会话和 cookie,因此就像手动登录一样(如果您现在在浏览器中打开您的网站,您应该已经登录).

Good thing is that Chrome persists session and cookies, so it is like logging in manually (if you now open your site in the browser you should be logged in).

这篇关于使用 chrome 扩展程序登录网站并从中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆