13

I am running python 2.7.2 I have lxml and cssselect installed

My code is

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 scraping a webpage that has titles and their associated links.

But I run into this error: 'lxml.etree._ElementTree' object has no attribute 'cssselect'

1 Answer 1

19

ElementTree does not have cssselect method, while HtmlElement object have it.

Use ElementTree.getroot to get HtmlElement object:

r = html.parse(start_url).getroot()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.