Skip to content

css选择器无法选择h3下的p标签 #203

@xujiang1

Description

@xujiang1
from parsel import Selector

html = "<h3>吉林大学社会科学学报<p>Jilin University Journal Social Sciences Edition</p></h3>"

sel = Selector(html)

print(sel.css("h3"))

print(sel.css("h3 > p::text").getall())

当我使用css选择器时 无法获取h3下的p标签,结果如下:


[<Selector xpath='descendant-or-self::h3' data='<h3>吉林大学社会科学学报</h3>'>]

[]

当我将p标签换成其他标签时可以正常获取:

from parsel import Selector

html = "<h3>吉林大学社会科学学报<em>Jilin University Journal Social Sciences Edition</em></h3>"

sel = Selector(html)

print(sel.css("h3"))

print(sel.css("h3 > em::text").getall())

结果:

[<Selector xpath='descendant-or-self::h3' data='<h3>吉林大学社会科学学报<em>Jilin University Jo...'>]

['Jilin University Journal Social Sciences Edition']

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions