【问题标题】:I want to scrape these product information我想抓取这些产品信息
【发布时间】:2021-10-04 13:25:47
【问题描述】:
import requests
from bs4 import BeautifulSoup
import pandas as pd
baseurl='https://twillmkt.com'
headers ={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'
}
r =requests.get('https://twillmkt.com/collections/denim')
soup=BeautifulSoup(r.content, 'html.parser')
tra = soup.find_all('div',class_='ProductItem__Wrapper')
productlinks=[]
Title=[]
Brand=[]
Colour=[]
for links in tra:
    for link in links.find_all('a',href=True)[1:]:
        comp=baseurl+link['href']
        productlinks.append(comp)
for link in productlinks:
    r =requests.get(link,headers=headers)
    soup=BeautifulSoup(r.content, 'html.parser')
    title=soup.find('h1').text
    Title.append(title)
    price=soup.find('span',class_="money").text
    Brand.append(price)
    Product_Features=soup.find_all('li').text 
    Colour.append(Product_Features)
    

df = pd.DataFrame(
    
    {"Title": Title, "Price": Brand,"Product_Features":Colour}
)
print(df)

我刮了标题和价格但是很难刮这些信息SIZE,product feature,material,model size,image 单页链接 https://twillmkt.com/products/light-blue-butterfly-print-slim-leg-denim?variant=39498848403534

【问题讨论】:

  • 我认为您应该能够搜索材料文本并对其进行解析
  • 你帮我抓取这些信息,我试图解析但我做不到

标签: python web-scraping beautifulsoup


【解决方案1】:

我将为您提供所需元素的 css 选择器。您可以通过soup.select() 捕获它们

大小:select[id^="product-select"] option

产品功能:div.ProductMeta__Description.Rte li

素材:div.ProductMeta__Description.Rte p:nth-of-type(2)

模型尺寸:div.ProductMeta__Description.Rte p:nth-of-type(3)

图片:div[id^="Image"] span img

【讨论】:

  • 好的,我试试然后告诉你
  • 当我写 .text (div.ProductMeta__Description.Rte li').text 他们给我错误
  • soup.select 生成像 find_all 这样的元素列表
  • 你能修改我的代码并提供答案吗?
  • 不,我不能,你的代码说你知道怎么做
猜你喜欢
  • 2022-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 1970-01-01
相关资源
最近更新 更多