[Answer]-How to scrape the name of a class form a web page?

1👍

Use xpath:

//div[@id="quranOutput"]/a[@class="key"]/@name

>>> import lxml.html
>>> 
>>> root = lxml.html.fromstring('''
... <html>
...     <body>
...         <div id="quranOutput">
...             <a class="key" name="1:1"></a>
...             <div class="verse ayahBox1" id="verse_1"></div>
...         </div>
...     </body>
... </html>''')
>>> 
>>> print root.xpath('//div[@id="quranOutput"]/a[@class="key"]/@name')
['1:1']

Leave a comment