首页 > 解决方案 > 使用漂亮的汤和 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"}))

在此处输入图像描述

标签: pythoncssbeautifulsouptags

解决方案


推荐阅读