【发布时间】:2020-01-23 21:37:57
【问题描述】:
所以,我试图从中抓取的网站是:https//viewyourdeal-gabrielsimone.com'
产品名称和价格在每个 div 下 class= "info-wrapper" 我可以毫无问题地提取价格,但是当我尝试提取产品标题时,它无法将其转换为文本作为其 href 链接。每个产品名称都在 href 下的 div 类下。 所以我的问题是,我如何抓取产品名称?
import json
from bs4 import BeautifulSoup
import requests
import csv
from datetime import datetime
url = 'https://viewyourdeal-gabrielsimone.com'
gmaInfo=[]
response = requests.get(url, timeout=5)
content = BeautifulSoup(response.content, "html.parser")
for info in content.findAll('div', attrs={"class" : "wrapper ease-animation"}):
gridObject = {
"title" : info.find('div', attrs={"class" : "title animation allgrey"}),
"price" : info.find('span', attrs={"class":"red-price"}).text
}
print(gridObject)
with open('index.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([gridObject])
【问题讨论】:
-
但是类是:title animation allyellow
-
@GiovaniSalazar 我相信有不同的系列。我想要实现的是将 allyellow 或 allgrey 变成我可以放在 xml 上的文本。该类是 href 的一部分
标签: python beautifulsoup e-commerce