Is it possible for lxml to work in a case-insensitive manner?

后端 未结 3 1590
野的像风
野的像风 2020-12-10 05:47

I\'m trying to scrape META keywords and description tags from arbitrary websites. I obviusly have no control over said website, so have to take what I\'m given. They have a

3条回答
  •  渐次进展
    2020-12-10 06:48

    You can use

    doc.cssselect.xpath("//meta[translate(@name,
        'ABCDEFGHJIKLMNOPQRSTUVWXYZ', 'abcdefghjiklmnopqrstuvwxyz')='description']")
    

    It translates the value of "name" to lowercase and then matches.

    See also:

    • XPath: How do you do a lowercase call in xpath
    • Xpath translation function turns things into lowercase?

提交回复
热议问题