如何使用PyQuery从元标记中获取内容值?

时间:2013-12-04 18:01:54

标签: python pyquery

<meta name="keywords" content="Ruby On Rails (Software), Authentication (Software Genre), Tutorial (Industry), howto, tips, tricks">

如何使用PyQuery从此元标记中获取content值?

from pyquery import PyQuery

def get_data(myurl):
    query = PyQuery(url=myurl)
    title = query("title").text()
    keyword = query("meta[name=keywords]").text()
    ...

1 个答案:

答案 0 :(得分:1)

你几乎成功了,缺少撇号字符来设置keywork

keyword = query("meta[name='keywords']").text()