我实际上是在从购物网站Flipkart抓取数据,并将其保存到包含产品名称,价格和等级的products.csv文件中。
for a in soup.find_all("a", href = True, attrs = {"class" : "_31qSD5"}):
name = a.find("div" , attrs = {"class":"_3wU53n"})
price = a.find("div" , attrs = {"class":"_1vC4OE _2rQ-NK"})
rating = a.find("div" , attrs = {"class":"hGSR34"})
products.append(name.text)
prices.append(price.text)
rating.append(rating.text)
df = pd.DataFrame({"Product_Name":products, "Prices":prices, "Ratings":rating})
上面的代码运行良好,但是下面的行给出了此错误:
ValueError: could not broadcast input array from shape (4) into shape (9)