python - 使用漂亮的汤和 css 访问标签
问题描述
我需要获取“Ubicación”和“Valoración 5 de 5”字段。
我在 Python 中有以下代码,但它没有打印出任何内容。请问你能帮帮我吗?
import urllib.request
from bs4 import BeautifulSoup
url=input("Introduce url: ")
req=urllib.request.Request(url,headers=headers)
html=urllib.request.urlopen(req).read()
soup=BeautifulSoup(html,"html.parser")
for puntuacion in soup:
if soup("span",{"class":"_fgdupie"})=="Ubicacion":
print(soup.find_all("span",{"class":"_1iu38l3"}))
解决方案
推荐阅读
- django - Distinct() 不适用于由 union() 产生的查询集
- flutter - 当 onPressed 在 BottomAppBar 图标项上时如何为孩子替换一个小部件
- unity3d - 如何从两个下拉列表中获取值并将它们与 if 进行比较?
- javascript - 如何比较午夜和其他指定时间之间的时间
- linux - 对可以循环遍历值的变量执行 if 选择语句?
- .net - F# - Int32.TryParse 的部分应用
- python-3.x - 使用 ConfigParser 时在配置文件中保留驼峰式大小写和注释
- javascript - 方括号前的逗号 - MDN 文档
- sqlite - sqflite batch.commit() 不适用于颤振
- networking - 如何使在 Virtual Box 中运行的应用程序可通过公共互联网访问