Thread: using ifsteam from a webpage??

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    31

    using ifsteam from a webpage??

    hi i was wondering if there is a way i can use ifstream to read from a web page and how i would do this at a guess
    Code:
    ifstream ins("www.webpage.com");
    im pretty sure this is wrong
    thanks in advance

  2. #2
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    you'd probably want to check the networking forum, I'm sure there's a way but you probably need some sort of protocol libarary. I'm just guessing though.

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    ok cool ty ill start a thread there or can this one be moved?

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    To the best of my knowledge, no one has written a TCP, HTTP, or any other kind of internet stream and made it publically available.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    well if there is a gap in the market maybe you should consider trying to make one?

    im gonna research the web again and see if i can find anything there

    thanks

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    You could create a class of your own and use some simple function like URLDownloadToFile() to download the source or the webpage to a file then make it read that file, save its info to memory somewhere ... I think there shoudl be an example of URLDownloadToFile somewhere on the boards.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by stien
    well if there is a gap in the market maybe you should consider trying to make one?
    No, the iostream interface is too unflexible for any serious net communication to be done over it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    if i post this link you can see what information i need from the web site

    but where it says zezima u will be able to put any name you want but im sure ill work that out just need to get that info



    http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=zezima


    this has the info i need for my program im sure ill be able to parse the data t omy program but i would have no idea how to make that class work?

    twomers if u could maybe point me in the right direction or give me a link to where i can find out how to get the webpage to download to my program i would appreciate it very much

    and again thank you
    Last edited by stien; 01-20-2007 at 05:35 AM.

  9. #9
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Sure I'll go one better, here's some source:


    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    
    #include <urlmon.h>
    
    #pragma comment( lib, "urlmon.lib" )	
    
    class URLstream 
    {
    
    private:
    	std::string PageURL;
    	std::string PageSource;
    
    	HRESULT ReturnValue;
    
    	void ReadFile ( void );
    
    
    public:
    	URLstream( void );
    	URLstream( std::string n_PageURL );
    
    	bool open( std::string n_PageURL );
    
    	void getpage( void );
    
    	friend std::istream &operator >> ( std::istream &in,  URLstream &instance );
    	friend std::ostream &operator << ( std::ostream &out, URLstream &instance );
    
    };
    
    void URLstream::ReadFile( void )
    {
    	std::ifstream in ( "tmp.tmp" );
    	std::string tmp;
    
    	if ( in )
    		while ( std::getline( in, tmp ) )
    			PageSource += tmp + "\n";
    
    	in.close();
    }
    
    URLstream::URLstream( void ) : ReturnValue( 0 ) 
    {}
    
    URLstream::URLstream( std::string n_PageURL ) : PageURL( n_PageURL ), ReturnValue( 0 )
    {
    	open( PageURL );
    }
    
    bool URLstream::open( std::string n_PageURL )
    {
    	PageURL = n_PageURL;
    
    	ReturnValue = URLDownloadToFile( NULL, PageURL.c_str(), "tmp.tmp", 0, NULL );
    
    	if ( ReturnValue == E_OUTOFMEMORY )
    		return false;
    
    	ReadFile();
    
    	return true;
    }
    
    std::istream &operator >> ( std::istream &in, URLstream &instance )
    {
    	in >> instance.PageURL;
    	instance.open( instance.PageURL );
    
    	return in;
    }
    
    std::ostream &operator << ( std::ostream &out, URLstream &instance )
    {
    	return out << instance.PageSource;
    }
    
    int main( void )
    {
    	URLstream URL;
    
    	std::cout<< "Enter the URL: ";
    	std::cin >> URL;
    	std::cout<< URL;
    
    
    	return 0;
    }
    You're gonna have to wait for the file to download properly though.

    EDIT: You're probably going to have to put in the whole address. with the http:// etc. The checking I put in there was minimal so you should put in more, and more functions too.
    Last edited by twomers; 01-20-2007 at 08:08 AM.

  10. #10
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    hey thanks alot i really appreciate it.
    at a quick glance i thinks its gone straight over my head but ill read through and study it properly. im sure that is just what i need


    thank you

    ok the first thing i dont understand is the <urlmon>
    and the urlmon.lib
    are these files included with my compiler? i use devcpp 4.9.8.0
    Last edited by stien; 01-20-2007 at 03:55 PM.

  11. #11
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Don't mention it. I like to give code every now and then

    Have you tried compiling it? I honestly don't know if they are included in dev or not. I wrote it using .... erm ... MSVC 2003 I think. the urlmon thing is just a library. Try compiling the code.

  12. #12
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    i compiled it but it says no such direcotry.
    but when i compiled as .h
    it worked?

  13. #13
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    You talking about the urlmon? That's meant to have a .h ... Is the code what you were looking for? You should probably split it into a .h and .cpp to make it more ... ethically correct. So it works?

  14. #14
    Registered User
    Join Date
    Jan 2007
    Posts
    31
    sorry i ment the code you wrote for me didnt compile when i saved it as url.cpp
    but it did compile when i saved it as url.h

    i just googled urlmon.h but i couldnt find any place to download it from have you got any ideas where i could find it?
    Last edited by stien; 01-20-2007 at 04:17 PM.

  15. #15
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    None I'm afraid. Perhaps that free MSVC thing that people are downloading ... can't remember what it's called. But that's not a guarantee! Hopefully someone else will know.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-27-2007, 08:47 PM
  2. Opening a webpage with C++
    By zach0616 in forum C++ Programming
    Replies: 4
    Last Post: 04-25-2005, 07:33 PM
  3. Downloading a webpage onto the disk?
    By Edin in forum Windows Programming
    Replies: 3
    Last Post: 11-23-2004, 01:37 AM
  4. Webpage in dialog
    By Mithoric in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2003, 08:41 PM
  5. calling c++ program from a webpage
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 10-04-2001, 09:41 AM