[英]Python & Scrapy output: "\r\n\t\t\t\t\t\t\t"
我正在學習使用 Scrapy 進行抓取,並且在某些代碼上遇到了一些問題,這給了我一個我不理解的奇怪輸出。 有人可以向我解釋為什么我得到一堆“\\r\\n\\t\\t\\t\\t\\t\\t\\t”
我在 Stack Overflow 上找到了這個解決方案: Remove an '\\\\n\\\\t\\\\t\\\\t'-element from list
但我想了解是什么導致了它。
這是我的代碼導致我的問題。 上面鏈接中的 Strip 方法解決了這個問題,但如前所述,我不明白它來自哪里。
import scrapy
import logging
import re
class CitySpider(scrapy.Spider):
name = 'city'
allowed_domains = ['www.a-tembo.nl']
start_urls = ['https://www.a-tembo.nl/themas/category/city/']
def parse(self, response):
titles = response.xpath("//div[@class='hikashop_category_image']/a")
for title in titles:
series = title.xpath(".//@title").get()
link = title.xpath(".//@href").get()
#absolute_url = f"https://www.a-tembo.nl{link}"
#absolute_url = response.urljoin(link)
yield response.follow(link, callback=self.parse_title)
def parse_title(self, response):
rows = response.xpath("//table[@class='hikashop_products_table adminlist table']/tbody/tr")
for row in rows:
product_code = row.xpath(".//span[@class='hikashop_product_code']/text()").get()
product_name = row.xpath(".//span[@class='hikashop_product_name']/a/text()").get()
yield{
"Product_code": product_code,
"Product_name": product_name
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.