打印对象十六进制值而不是值

时间:2018-04-24 22:39:01

标签: python python-3.x output

使用python 3.5。

当我的代码打印出bs.parse()时,它会显示对象的十六进制值,而不是bs.parse的值。

我在这里做错了什么?

class BrickSetSpider(scrapy.Spider):
    name = "website_spider"

    site_search_url = 'website.com'

    website_base = 'http://www.websitenew.com/search?id=site:'
    start_urls = [website_base + site_search_url]
    def parse(self, response):
        website_result_list = []
        website_result_page = []

        NEXT_PAGE_SELECTOR = 'a.sb_pagN ::attr(href)'
        next_page = response.css(NEXT_PAGE_SELECTOR).extract_first()
        if next_page:
            yield scrapy.Request(
                response.urljoin(next_page),
                callback=self.parse,
        headers={'referer':self.start_urls}
            )
            website_result_page.append(response.urljoin(next_page)) 

        #create LIST into SET to remove duplicates then change SET back to LIST.
        set(website_result_page)
        list(website_result_page)

        for brp in website_result_page:   
            return("printing brp: " + brp)

bs = BrickSetSpider()
print(bs.parse('200'))

返回: <generator object BrickSetSpider.parse at 0x7f6f609c8f10>

1 个答案:

答案 0 :(得分:0)

那只是使用对象的通用打印功能。十六进制值是对象的内存地址。由于对象是生成器,因此您可以尝试将其强制转换为列表

print(list(bs.parse('200')))