简体   繁体   中英

How to extract metadata as key value pair using lxml python?

I have to scrape meta data as key-value pair from web site.检查 HTML 图像

meta_name = tree.xpath("//meta[@name]/@content")

This will give me value(eg: John Doe) for meta_name but doesn't specify the key(eg:author).

ps: I mentioned example from the uploaded picture

meta_name = tree.xpath("//meta[@name]")  
for elem in meta_name:
    print(elem.attrib)

elem.attrib will give us the dict of attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM