Search code examples
c++google-chrome-extensionfirefox-addon

How-to: Send text from webpage and send to external application


i'm writing a program for my algorithm class that is supposed to be able to traverse a webpage, find a random address, and then using a browser extension(Firefox/Chrome), it should do a Google Maps search for that address. I literally just thought that maybe trying to use the extension to capture text and put it into a text file and then make my program read that text file would be a good idea, but i have no clue as to how that would be implemented.

My code so far (Don't worry, after a Window UI, it will get longer. This is just a test console app):

#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <windows.h>

using namespace std;



int main ()
{
  string address;

  cout << "Please input address: ";
//cin >> address;
  getline(cin, address); 
//word_list = getRecursiveURLs(url, DEPTH)
//return cleaner(word_list) 

//string address = "Houston, Tx ";
  std::string str = "http://mapof.it/" + address;
//cout << mapSearch;
  const char * c = str.c_str();

  ShellExecute(NULL, "open", c, NULL, NULL, SW_SHOWNORMAL);     
}

Right now, my code takes in an address and adds it to the end of a "Mapof.it" url that basically initiates a GMaps search.


Solution

  • It look like user is interact with your C++ program. It doesn't need to communicate with browser progress.

    You can send http request from C++ program, fetch the reponse text, then parse it.

    First, you try to find whether the website provide a api url which return json/xml format, because json/xml is easier to parse. For example, Google Map does provide api.

    If not, try to use regular expression to parse html, or find some DOM handle library to parse it with DOM.

    If your result text can't not extract from raw, it create by JavaScript dynamically, you can find some "headless browser" library to help you.

    If you need a full feature browser, use QT, it provide QtWebkit widget.