部分html代码如下
'''
<div class="QuestionPage" itemscope="" itemType="http://schema.org/Question">
<meta itemProp="name" content="\u96fe\u973e\u771f\u7684\u89e3\u51b3\u4e0d\u4e86\u4e48\uff1f"/>
<meta itemProp="url" content="https://www.zhihu.com/question/22863429"/>
<meta itemProp="keywords" content="\u5317\u4eac,\u73af\u5883\u4fdd\u62a4,\u7a7a\u6c14\u8d28\u91cf,PM 2.5"/>
<meta itemProp="answerCount" content="841"/><meta itemProp="commentCount" content="57"/>
<meta itemProp="dateCreated" content=""/>
'''
我的xpath表达式如下
tree.xpath('//meta[itemProp="keywords"]/@content')
无法匹配到结果
但是使用
tree.xpath('//meta/@content')
可以匹配到所有的meta标签结果
结果中含有目标字段内容
暂未解决该问题,在此记录已解决
解决方案如下,改itemProp 为 itemprop
tree.xpath('//meta[@itemprop="keywords"]/@content')