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

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

问题描述

我正在开发一个Chrome / Chromium扩充功能,将从学校系统中读取成绩。问题是,网站不记得已记录的用户。因为这个,我不能使用AJAX。

I am developing a Chrome/Chromium extension that will be reading school grades from 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'am logged to that page on other tab. But I want to login to that page in background and automaticly. Solution may be maybe iframe tag, but Chrome/Chromium dont allow me to read and manipulate with iframe content. Is there any solution how to manipulate in page as logged user? Thank you

推荐答案

您可以从背景页面通过javascript模拟表单提交。首先,您需要仔细检查通过登录表单发送的数据以及发送到哪个URL(在发送之前,可以使用javascript更改表单,因此您需要知道实际发送的是什么,而不仅仅是< form> ; 元素)。您可以使用Chrome的控制台进行简单操作,如果还不够,那么 Tamper Data插件(适用于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天全站免登陆