Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Beautifulsoup+HTML…如何忽略几个h3类_Python_Html_Css_Web Scraping_Beautifulsoup - Fatal编程技术网

Python Beautifulsoup+HTML…如何忽略几个h3类

Python Beautifulsoup+HTML…如何忽略几个h3类,python,html,css,web-scraping,beautifulsoup,Python,Html,Css,Web Scraping,Beautifulsoup,我得到了以下代码: from bs4 import BeautifulSoup import requests import re source = requests.get('https://tienda.mimo.com.ar/mimo/junior/ropa-para-ninas.html').text soup = BeautifulSoup(source, 'lxml') for name_product, old_price, special_price in zip(soup

我得到了以下代码:

from bs4 import BeautifulSoup
import requests
import re

source = requests.get('https://tienda.mimo.com.ar/mimo/junior/ropa-para-ninas.html').text

soup = BeautifulSoup(source, 'lxml')

for name_product, old_price, special_price in zip(soup.select('h3', class_='titprod'), 
                                                  soup.select('span[id^="old-price"]'),
                                                  soup.select('span[id^="product-price"]')):
    print(f'Name: {name_product.text.strip()} |  Old price = {old_price.text.strip()} | Discounted price = {special_price.text.strip()}')
这将产生:

名称:商业银行和商业银行相关业务推广协议的签署人|原价=295美元|折扣价=236美元 名称:“格雷西亚斯·波尔·苏克里比特通讯!”旧价=990美元|折扣价=743美元 名称:Elegípor talle |原价=2.300美元|折扣价=1.725美元 名称:TAPABOCAS |原价=1.550美元|折扣价=1.163美元 名称:雷米拉小镇|旧价=2.990美元|折扣价=2.243美元 姓名:CAMISOLA NENA DELFI |旧价=1.990美元|折扣价=1.493美元我不得不改变

soup.select('h3', class_='titprod'),
为了


正如@AndrejKessely在评论中所建议的那样,它工作得非常完美

问题在于您使用的选择方法是错误的。要选择class=titprod的all,您需要编写soup。选择'h3.titprod'

class=参数属于.find和.find\u所有不使用CSS选择器的函数

链接到bs4文档中的


bs4文档中的示例。

我无法访问该站点,但尝试更改soup。请选择'h3',class='titprod'为soup。选择'h3.titprod'。select方法没有class_=参数。它在@AndrejKesely中工作得很好…只是为了学习为什么它不采用我不希望采用这种方式的行?我将用解释写一个答案。请不要发布代码、数据或回溯的图像。复制并粘贴为文本,然后将其格式化为代码选择它并键入ctrl-k。。。
soup.select('h3.titprod')