【发布时间】:2021-09-09 08:10:11
【问题描述】:
我正在抓取这个site,我试图抓取的数据是产品图片、产品名称、价格和发布日期。
import requests
import time
from bs4 import BeautifulSoup
from discord_webhook import DiscordWebhook, DiscordEmbed
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'}
url = "https://www.adidas.com.sg/release-dates"
productsource = requests.get(url,headers=headers,timeout=15)
productinfo = BeautifulSoup(productsource.text, "lxml")
#webscraper
for item in productinfo.select(".plc-product-card___1tVAm plc-product-card-mobile___3bmHS"):
pname = item.find("div", class_='plc-product-name___2cofu gl-product-card__name gl-label gl-label--m gl-label--condensed').get_text(strip=True) #product title
price = item.find("div", class_="gl-price-item notranslate gl-label--m").get_text(strip=True) #product price
imagelink = item.find('img')['src'] #product image link
plink = f"https://www.adidas.com.sg/{item.a['href']}" #to get product page link
pdate = item.find("div",class_="gl-price-item notranslate gl-label--m").get_text()
print(pname,'\n',price,'\n',imagelink,'\n',plink,'\n',pdate)
运行此脚本时,它不会返回任何结果或错误,终端只是空白并且不会停止运行。不太清楚这里有什么问题。谁能指出我正确的方向?
【问题讨论】:
-
您对
get_text的最终调用需要括号:.get_text()。事实上,pdate将是一个函数,而不是一个字符串。 -
哎呀,我在复制代码时错过了它。感谢您让我知道我编辑了它。
-
@meliz 是否正确
productinfo.select(".plc-product-card___1tVAm plc-product-card-mobile___3bmHS")请检查!
标签: python web-scraping beautifulsoup python-requests webautomation