Html响应对象没有属性文本

时间:2014-12-27 14:55:51

标签: python web-scraping scrapy

import scrapy

from bs4 import BeautifulSoup


class Spider(scrapy.Spider):
    name = "crawl"
    start_urls = [url]

    def parse(self, response):
        soup = BeautifulSoup(response.text)
        print soup.prettify()

我有这大块代码。是#39; m使用scrapy,当我执行它时,我收到此错误:

  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 577, in _runCallbacks
    current.result = callback(current.result, *args, **kw)
  File "/vagrant_data/cars_scraper/cars_scraper/spiders/__init__.py", line 17, in parse
    soup = BeautifulSoup(response.text)
exceptions.AttributeError: 'HtmlResponse' object has no attribute 'text'

1 个答案:

答案 0 :(得分:1)

使用Response.body属性代替text