我试图得到的标题和描述的具体产品写在希腊语我想输出在希腊语以及。但它是不是显示完整的标题。为什么?
这是我的代码。
import scrapy
class FitcoupleSpider(scrapy.Spider):
name = 'fitcouple'
allowed_domains = ['fitcouple360.gr']
start_urls = ['https://fitcouple360.gr/product/herbalife-f1-threptika-meal-bars-sokolata/']
def parse(self, response):
products = response.xpath(".//div[@class='content-page container']/div[contains(@class,'single-product product')]")
for product in products:
title = product.xpath("//div//div[@class='fixed-content']/h1/text()").get()
print(title)
产品名称为“Θρεπτικό πρωτε νο χο ρόφημα康宝莱配方1 υγιεινό γε μα咖啡拿铁550g”
但我得到的输出“康宝莱F1
2022-09-27 22:49:55 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://fitcouple360.gr/product/herbalife-f1-threptika-meal-bars-sokolata/> (referer: None)
**Herbalife F1 Θρεπτικά Meal Bars σοκολάτα**
2022-09-27 22:49:56 [scrapy.core.engine] INFO: Closing spider (finished)
2022-09-27 22:49:56 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
2条答案
按热度按时间23c0lvtd1#
以上URL包含产品标题:康宝莱F1的巧克力棒这是正确的.如果不是那么你已经注入了另一个链接,请证明与链接的标题是否正确与否
wixjitnu2#
通过
xpath("//div//div[@class='fixed-content']/h1/text()")
得到的html部分不包含Θρεπτικό πρωτεϊνούχο ρόφημα Herbalife Formula 1 υγιεινό γεύμα Café Latte 550g
,而是包含Herbalife F1 Θρεπτικά Meal Bars σοκολάτα
问题不在于标题或希腊语编码
这个问题要么是错误xpath,要么是动态更改数据的js,从而使您得到错误的产品