Hi, I'm a beginner in C++ and I need some help how to get a website's source code and save it into a string.

Oh, and also: how can I then search the source for a specific keyword AND how can I "extract" a word between 2 keywords ? Here's what I mean:

$source = _INetGetSource("http://www.google.com") ; get websites source
$stringBetween = _StringBetween($source,"a keyword","second keyword") ; this extracts a word between those two keywords

If StringInStr($source, "Google") Then ; this searches the source for a keyword Google
; do something
EndIf

This code is in autoit and I hope it'll help you understand what I need help with.

Recommended Answers

All 8 Replies

I found this with google -- and you could have too. But I don't know if it answers your question.

no, I gave the autoit code as an example of what I mean.
I want to know how to do the same thing but in C++

If it's on windows, 1 line of C code with Win32 api...

On unix or windows you could use libcurl.

marco: What's the windows one-liner?

I don't know about one line, but it only takes a few lines with Wininet in Win32. And I'm sure you'll need more than one string to store a whole page in.

... And I'm sure you'll need more than one string to store a whole page in.

What's a problem? For example, in VC++ source.max_size() for std::string source is equal to 4294967294 bytes ;)

What's a problem? For example, in VC++ source.max_size() for std::string source is equal to 4294967294 bytes ;)

I've downloaded files larger than 4GB(till the game got a smart installer). Although I doubt he'll ever retrive something that LARGE. lol

What's an enviable your channel bandwidth ;)...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.