Python-ccsselect带空格
我使用lxml在Python中解析html文件 我使用cssselect。 诸如此类:Python-ccsselect带空格,python,html,css,lxml,Python,Html,Css,Lxml,我使用lxml在Python中解析html文件 我使用cssselect。 诸如此类: from lxml.html import parse page = parse('http://.../').getroot() img = page.cssselect('div.photo cover div.outer a') # problem 但我有个问题。HTML中的类名中有空格: <div class="photo cover"><div class=outer>
from lxml.html import parse
page = parse('http://.../').getroot()
img = page.cssselect('div.photo cover div.outer a') # problem
但我有个问题。HTML中的类名中有空格:
<div class="photo cover"><div class=outer>
<a href=...
要将div
与photo
和cover
类匹配,请使用div.photo.cover
img = page.cssselect('div.photo.cover div.outer a')
不要将class=“photo cover”
视为带有photo cover
作为值的class属性,而应将其视为带有photo
和cover
作为值的class属性