How would I get the headers text from any website with httpservice?
I tried and it just printed everything.
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 <h1>( )
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 </h1>