Object 'lxml.etree._ElementTree' does not have attribute 'cssselect'

I am running python 2.7.2 I have lxml and cssselect installed

My code

from lxml import etree, html r = html.parse(start_url) all_titles = r.cssselect('span.titles') #should return a list of results all_urls = r.cssselect('span.links') #and this as well 

I am clearing a webpage with names and related links.

But I ran into this error: Object 'lxml.etree._ElementTree' does not have attribute 'cssselect'

+7
python lxml
source share
1 answer

ElementTree does not have a cssselect method, but the HtmlElement object has it.

Use ElementTree.getroot to get an HtmlElement object:

 r = html.parse(start_url).getroot() 
+10
source share

All Articles