Firefox addon: how to grab data from a web page?

purpose

I am trying to create a generic response database for a website form. The form is a description of the specifications of the computer hardware, and I am trying to make the other fields fill in automatically based on the model field. Extension with two buttons, "fill" to be based on the model field, check the database for the corresponding record, and then fill in the data in the forms based on this. The second button will "save" which will take the data in the fields and marry it into the model field and put it into the database.

Question

So my main question is interacting with the webpage itself, how do I get the data from the webpage, and then how do I make the changes to the fields?

+3


source to share


1 answer


So my main question is interacting with the webpage itself, how do I get the data from the webpage, and then how do I make the changes to the fields?

You can do this with Firefox Add-on SDK Page-mod, click here for documentation

Here's an example of getting data:

Example Page-Mod



/lib/main.js:

var tag = "p";
var data = require("sdk/self").data;
var pageMod = require("sdk/page-mod");

pageMod.PageMod({
  include: "*.mozilla.org",
  contentScriptFile: data.url("element-getter.js"),
  onAttach: function(worker) {
    worker.port.emit("getElements", tag);
    worker.port.on("gotElement", function(elementContent) {
      console.log(elementContent);
    });
  }
});

      

/data/element-getter.js:

self.port.on("getElements", function(tag) {
  var elements = document.getElementsByTagName(tag);
  for (var i = 0; i < elements.length; i++) {
    self.port.emit("gotElement", elements[i].innerHTML);
  }
});

      

+5


source







All Articles