python - BeautifulSoup 找不到元标记信息
问题描述
所有三个标题都返回“无”。但是,当我查看页面源时,我可以清楚地看到twitter:title
,og:title
并且og:description
清楚地存在。
url = 'https://www.vox.com/culture/2018/8/3/17644464/christopher-robin-review-pooh-bear-winnie'
response = requests.get(url)
soup = BeautifulSoup(response.text, "lxml")
title = soup.find("meta", property="twitter:title")
title2 = soup.find("meta", property="og:title")
title3 = soup.find("meta", property="og:description")
print("TITLE: "+str(title))
print("TITLE2: "+str(title2))
print("TITLE3: "+str(title3))
解决方案
soup.find("meta", property="twitter:title")
必须是soup.find("meta", {"name": "twitter:title"})
(它是一个名称,而不是一个属性)。其他两行对我来说很好。
推荐阅读
- amazon-web-services - AppSync/DynamoDB 中的附加解析程序是否会为读取操作计费两次?
- ruby - 如何从Ruby中的人性化字符串中去人性化以前的时间?
- python - 如何删除以某事开头和结尾的子字符串?
- typescript - npm 模块无法导入
- python - 验证准确率达到 90% 后没有提高
- java - Amadeus POI Java 要求下一个,最后一个不工作
- c# - 检查空 texboxes 并显示消息框
- node.js - 使用 NodeJS 回调上传到 S3 存储桶必须是一个函数。收到未定义
- node.js - 具有内容长度限制的签名 URL
- mongodb - 如何从 map-reduce 集合中获取 _id 元素