Scrapping: How to fetch an attribute in a <abbr> tag
Question: I am using **lxml and python** to scrap through a page. The link to the page
is **[HERE](http://www.insiderpages.com/b/3721895833/central-kia-of-irving-
irving)**. The hiccup I face right now is how to fetch the attribute in the
tag. For example the 3 Gold stars at the top of the page, they have a html

    
    
    <abbr title="3" class="average rating large star3">★★★☆☆</abbr>
    

Here I want to fetch the title so that I know how many stars did this location
get.

I have tried doing a couple of things including this:

    
    
    response = urllib.urlopen('http://www.insiderpages.com/b/3721895833/central-kia-of-irving-irving').read()
    mo = re.search(r'<div class="rating_box">.*?</div>', response)
    div = html.fromstring(mo.group(0))
    title = div.find("abbr").attrib["title"]
    print title
    

But does not work for me. Help would be appreciated.


Answer: [Don't use regex to extract data from
html.](http://stackoverflow.com/a/1732454/843822) You have lxml, use it's
power ([XPath](http://lxml.de/xpathxslt.html#xpath)).

    
    
    >>> import lxml.html as html
    >>> page = html.parse("http://www.insiderpages.com/b/3721895833/central-kia-of-irving-irving")
    >>> print page.xpath("//div[@class='rating_box']/abbr/@title")
    ['3']
    

