【发布时间】:2021-05-10 08:56:13
【问题描述】:
我正在尝试抓取 Shopee 的产品名称、价格和图片。但是,我似乎无法提取图像。是不是因为html?我似乎无法在 dataImg 中找到图像类
import pandas as pd
from selenium import webdriver
from bs4 import BeautifulSoup
driver =webdriver.Chrome('chromedriver')
products=[]
prices=[]
images=[]
driver.get('https://shopee.co.id/search?keyword=laptop')
content=driver.page_source
soup=BeautifulSoup(content)
soup
for link in soup.find_all('div',class_="_3EfFTx"):
print('test')
print(link)
for link in soup.find_all('div',class_="_3EfFTx"):
#print(link)
dataImg=link.find('img',class_="_1T9dHf V1Fpl5")
print(dataImg)
name=link.find('div',class_="_1Sxpvs")
#print(name.get_text())
price=link.find('div',class_="QmqjGn")
#print(price.get_text())
if dataImg is not None:
products.append(name.get_text())
prices.append(price.get_text())
images.append(dataImg['src'])
df=pd.DataFrame({'Product Name':products,'Price':prices,'Images':images})
df
【问题讨论】:
-
在 driver.page_source 之前添加一些等待,由于页面加载,它不会检索值。
标签: python pandas selenium web-scraping beautifulsoup