我在抓取目标站点时遇到问题,例如。https://www.trendyol.com/camasir-yikama-urunleri-x-c103809
我脚本:
def parse(self, response):
soup = BeautifulSoup(response.text, 'lxml')
data = [json.loads(m.group(1)) for m in re.finditer(r"(?<=\=)(.*?)(?=\};)", response.text)]
for elem in data['product']['variants']:
print(elem['name'])
而目标json数据的例子是:
window.__SEARCH_APP_INITIAL_STATE__={"slpName":"","products":[{"id":76179753,"name":"Renk Ayırıcı Mendil Çamaşır Makinesi Için 50'li","images":["/ty166/product/media/images/20210828/22/123579644/130296764/1/1_org_zoom.jpg"],"imageAlt":"DOMOL Renk Ayırıcı Mendil Çamaşır Makinesi Için 50'li","brand":{"id":110099,"name":"Domol"},"tax":18,"businessUnit":"Ev Bakım ve Temizlik","ratingScore":{"averageRating":4.766536964980545,"totalCount":5140},"showSexualContent":true,"productGroupId":65110387,"hasReviewPhoto":true,"cardType":"PRODUCT","sections":[{"id":"12"},{"id":"16"},{"id":"1"},{"id":"2"}],"variants":[{"attributeValue":"Tek Ebat","attributeName":"beden","price":{"discountedPrice":54.5,"buyingPrice":0,"originalPrice":54.5,"sellingPrice":54.5},"listingId":"660413b49cdf25530a31d3666dfaae1a","campaignId":602622,"merchantId":179281,"discountedPriceInfo":"","hasCollectableCoupon":true}],"categoryHierarchy":"Renk Koruyucu Mendil/Çamaşır Yan Ürün/Süpermarket/Ev Bakım ve Temizlik/Çamaşır Yıkama","categoryId":2357,"categoryName":"Renk Koruyucu Mendil","url":"/domol/renk-ayirici-mendil-camasir-makinesi-icin-50-li-p-76179753","merchantId":179281,"campaignId":602622,"price":
我怎么刮
产品名称、价格、ID、URL
从这个json数据中?
- 谢谢-谢谢
1条答案
按热度按时间kiayqfof1#
请尝试:
印刷品: