在python中通过scrapy抓取网站时收到以下错误:

时间:2018-05-11 10:57:22

标签: python-2.7 scrapy

  

错误:UnicodeEncodeError:' charmap'编解码器无法对字符进行编码   ü' \ u201c'在位置0:字符映射到

代码:# - - 编码:utf-8 - -

import scrapy


class Spider1Spider(scrapy.Spider):
    name = 'spider_1'
    allowed_domains = ["quotes.toscrape.com"]
    start_urls = (
        'http://quotes.toscrape.com/' ,
        )

    def parse(self, response):
     x=response.xpath('//*[@class="quote"]')
     for quotes in x:
        text= x.xpath('.//*[@class="text"]/text()').extract_first()
        author= x.xpath('.//*[@class="author"]/text()').extract_first()
        Tags= x.xpath('.//*[@class="keywords"]/@content').extract_first()

        print '\ n'
        print text
        print author
        print Tags
        print '\ n'

Problm:如果我只使用extract_first,那么它会抛出错误,否则我们只使用提取。它会罚款。

任何人都可以请求帮助,因为我是编程世界的新手并期待积极的解决方案。

0 个答案:

没有答案