Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

 

Webscrape

A Web 'Screen Scraper' 

mailto:info@webscrape.com


Calling PageScrape from C++

The easiest way to use PageScrape from C++ (or C) is to use popen(), or as it's called in Microsoft's C runtime library _popen().  This function launches the specified program and returns a handle to its Stdout which can be simply read like a file.

#include <process.h>
#include <iostream>
#include <sstream>

using namespace std;

#define popen _popen
#define pclose _pclose

int main(int argc, char* argv[])
{
  string program = "pscrape.exe";
  string ticker = "msft";
  string url = "moneycentral.msn.com/scripts/webquote.dll?iPage=lqd&Symbol=";

  url += ticker;

  string regEx = "Real-time quotes.*(\\d+\\.\\d+)<";

  stringstream command;
  command << program << " -u\"" << url << "\" -e\"" << regEx << "\"";

  FILE* fp = popen(command.str().c_str(), "r");

  if (fp == NULL)
  {
    cerr << "Could not launch PageScrape" << endl;
    return -1;
  }

  char pBuf[2048];

  while (!feof(fp))
  {
    if (fgets(pBuf, 2047, fp) != NULL)
      cout << pBuf;
  }

  pclose(fp);

  return 0;
}