Pedro Assunção

Grabbing title tag from web page

At least a couple of options, the first using BeautifulSoup:

import urllib
import BeautifulSoup

soup = BeautifulSoup.BeautifulSoup(urllib.urlopen("https://www.google.com"))
print soup.title.string

And the second one using lxml:

import lxml.html
t = lxml.html.parse(url)
print t.find(".//title").text

Related:

  1. Several years of email statistics – code included Out of boredom, I decided to create a couple of...
  2. Earthquake information in Ruby Here’s a little script to get the latest earthquakes worldwide...


Categorised as: code snipplets, computers, software development, tips


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>