Find the answer to your Linux question:
Results 1 to 8 of 8
hello i'd like to write a simple program in c++ that would go to a couple of websites, extract a few sentences and write them to a file on my ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2005
    Location
    cracow, poland
    Posts
    76

    simple networking in c++


    hello

    i'd like to write a simple program in c++ that would go to a couple of websites, extract a few sentences and write them to a file on my disk.

    could you please tell me how i could do it or where i could look for help?

  2. #2
    Just Joined!
    Join Date
    Feb 2005
    Location
    Delft, Holland
    Posts
    95
    Oh an email-address scanner?

  3. #3
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I'd say it would be far simpler to do that with a shell script:
    Code:
    wget -qO - http://some/address | grep the-sentence-you-want
    If that's too simple for you, I'd still recommend using Perl instead of C or C++.

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Mar 2005
    Location
    cracow, poland
    Posts
    76
    Morgoth:
    lol, no
    i'm an admin at p2p.info.pl and need to update p2p networks statistcs quite often. i just don't feel like visiting quite a lot of sites every now and then and thought i could perhaps make it slightly more automatic.

    Dolda2000:
    thanks, that is really simple
    however, this is not very exactly what i need. i've just written above what i need the program for.
    is there a way to make it only show what's after a given string, and not the whole line (which happens to be really long sometimes, take a look at google's main page for instance).
    more precisely, if it says "currently users online: 200", can i make it only show "200"?

  6. #5
    Just Joined!
    Join Date
    Jun 2005
    Posts
    13
    caminoix,

    For what you're doing, it sounds like you really need to look at perl and regex's.
    First look at the perl man page. Then,
    For a quick start on regexes try: man perlrequick
    And for easy access to documents on the web look at man lwpcook, particulary the parts regarding the LWP::Simple module.
    The regex's will allow you to pick out exactly what you want with precision.
    If you need to do stuff like this at all regularly it will be well worth your time.

    ericffff

  7. #6
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    You don't need to resort to Perl for that -- sed will do just find. Try this:
    Code:
    wget -qO - http://www.your.url/here | sed -n 's/^.*users currently online: *\([0-9][0-9]*\).*$/\1/ip'
    That ought to work for you, but I haven't actually tested it or anything, so there may well be typos in it.

  8. #7
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    I assume there is a single space after the online: part.
    By the way what does ip stand for at the end ? p is for print but
    what does the i do ?

  9. #8
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Indeed there is a single space after `online:'. As you probably understood, I added the asterisk in case the actual page contains any number of spaces.

    The `i' is really a GNU extension, so don't try to be all to portable with it. What it does is match the regex case-insensitively.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •