Zoker
Zoker

Reputation: 2059

Get website title without displaying it

I want to get the title of a webpage without actually displaying the website inside my app.

Only want to receive the title. (or header information)

I searched stack, but were not able to find a solution

Upvotes: 0

Views: 55

Answers (1)

Abdul Fatir
Abdul Fatir

Reputation: 6357

Okay, so I won't spoon-feed you with code, but you can do it in two ways.

  1. Using an HTML parser - Load the website data into the HTML parser and look for the text in <title> tag.
  2. Manually using HttpURLConnection.

a) Connect to the website using HttpURLConnection.
b) Read the first few thousand bytes (it will most probably contain the <title> tag).
c) Search for the Title using this regex <title>(.*)<\/title>. Check the regex here.

If you want to know how to use regex for title extraction, check the answer linked by GeorgeGkas.

Upvotes: 1

Related Questions