通过产品报废来提取信息

2024-10-03 00:27:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习如何通过抓取电子商务来获取产品信息,我已经取得了一些成就,但有些部分我无法解析

使用此代码,我可以获取标签中的信息

from bs4 import BeautifulSoup


soup = BeautifulSoup('A LOT OF HTML HERE', 'html.parser')
productos = soup.find_all('li', {'class': 'item product product-item col-xs-12 col-sm-6 col-md-4'})
for product_info in productos:

  # To store the information to a dictionary
  web_content_dict = {}
  web_content_dict['Marca'] = product_info.find('div',{'class':'product-item-manufacturer'}).text
  web_content_dict['Producto'] = product_info.find('strong',{'class':'product name product-item-name'}).text
  web_content_dict['Precio'] = product_info.find('span',{'class':'price'}).text


  
  # To store the dictionary to into a list
  web_content_list.append(web_content_dict)
df_kiwoko = pd.DataFrame(web_content_list)

我可以从以下方面获取信息:

<div class="product-item-manufacturer"> PEDIGREE </div>

我想从这部分中获取信息:

<a href="https://www.kiwoko.com/sobre-pedigree-pollo-en-salsa-100-g-pollo- 
y-verduras.html" class="product photo product-item-photo" tabindex="-1" 
data-id="PED321441" data-name="Sobre Pedigree Vital Protection pollo y 
verduras en salsa 100 g" data-price="0.49" data-category="PERROS" data- 
list="PERROS" data-brand="PEDIGREE" data-quantity="1" data-click="" 

例如,以“Perros”为例

data-category="PERROS"

如何从不在>;之间的零件获取信息&书信电报;并取“”之间的元素


Tags: textnamedivinfowebdatacolcontent