使用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>
答案 0 :(得分:0)
那只是使用对象的通用打印功能。十六进制值是对象的内存地址。由于对象是生成器,因此您可以尝试将其强制转换为列表
print(list(bs.parse('200')))