Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Get a websites headers text (<h1>) with httpservice and print it?

How would I get the headers text from any website with httpservice?

I tried and it just printed everything.

3 comments

0

WebsiteHtmlString:match('

(.*)

') --That might help whoever is willing to take on this question.

0

you printed the html

0

I disagree with your use of the greedy match, M39a9am3R

1 answer

✓ Accepted answer

String patterns
Oh do I love these things

You're going to want to extract it using string.match.

local FirstH1 = HttpService:GetAsync("http://www.example.com/"):match('<h1>(.-)</h1>');

Why does it work?
string.match takes two arguments - The string to match against, and the pattern to match with. Because the string library is inherited by all strings, match can be called as a method of a string. This in turn means that the returned string is implied as the first argument. The pattern is therefore the 'first' argument, which works like so:

  • <h1> matches

  • ( ) is a capture. This is the part that match returns when it finds it.
  • . matches any character.
  • - matches the preceding set 0 or more times, using a non-greedy matching: It will match as few occurrences as possible to satisfy the pattern.
  • </h1> matches

This discussion is preserved as it was. New answers, comments, and votes are closed.