Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
8iw 10
8 years ago

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

I tried and it just printed everything.

0
WebsiteHtmlString:match('<h1>(.*)</h1>') --That might help whoever is willing to take on this question. M39a9am3R 3210 — 8y
0
you printed the html UniversalDreams 205 — 8y
0
I disagree with your use of the greedy match, M39a9am3R User#6546 35 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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>
Ad

Answer this question