我一直在尝试使绘图更加平滑,就像在这里所做的那样,但是我的Xs是与linspace不兼容的日期时间对象。
我将X转换为matplotlib日期:
Xnew = matplotlib.dates.date2num(X)
X_smooth = np.linspace(Xnew.min(), Xnew.max(), 10)
Y_smooth = spline(Xnew, Y, X_smooth)
Run Code Online (Sandbox Code Playgroud)
但是然后我得到了一个空图,因为我的Y_smooth是
[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
由于某些未知的原因。
我该如何进行这项工作?
编辑
这是我打印变量时得到的,但没有发现异常:
X : [datetime.date(2016, 7, 31), datetime.date(2016, 7, 30), datetime.date(2016, 7, 29)]
X new: [ 736176. 736175. 736174.]
X new max: 736176.0
X new min: 736174.0
XSMOOTH [ 736174. 736174.22222222 736174.44444444 736174.66666667
736174.88888889 736175.11111111 736175.33333333 736175.55555556
736175.77777778 736176. ]
Y [711.74, 730.0, 698.0]
YSMOOTH [ 0. 0. …Run Code Online (Sandbox Code Playgroud) 我有一个处理链中请求的蜘蛛,meta用于产生具有来自多个请求的数据的项目。我用来生成请求的方式是在第一次调用 parse 函数时启动所有请求,但是,如果我有太多链接要请求,则不会安排所有请求,并且最终我没有得到我需要的一切。
为了解决这个问题,我试图让蜘蛛一次请求 5 个产品,当蜘蛛空闲时再次请求(通过在 中连接信号from_crawler)。问题是,由于我的代码现在是,spider_idle 不运行该request函数并且蜘蛛立即关闭。就好像蜘蛛没有闲着一样。
这是一些代码:
class ProductSpider(scrapy.Spider):
def __init__(self, *args, **kwargs):
super(ProductSpider, self).__init__(*args, **kwargs)
self.parsed_data = []
self.header = {}
f = open('file.csv', 'r')
f_data = [[x.strip()] for x in f]
count=1
first = 'smth'
for product in f_data:
if first != '':
header = product[0].split(';')
for each in range(len(header[1:])):
self.header[header[each+1]] = each+1
first = ''
else:
product = product[0].split(';')
product.append(count)
count+=1
self.parsed_data.append(product)
f.close()
@classmethod
def from_crawler(cls, crawler, *args, **kwargs): …Run Code Online (Sandbox Code Playgroud) 我创建了一个非常慢的新 Scrapy 蜘蛛。它每秒只能抓取大约两页,而我创建的其他 Scrapy 爬虫的抓取速度要快得多。
我想知道是什么导致了这个问题,以及如何解决这个问题。该代码与其他蜘蛛并没有太大不同,我不确定它是否与问题有关,但如果您认为可能涉及到它,我会添加它。
事实上,我的印象是请求不是异步的。我从来没有遇到过这种问题,而且我对 Scrapy 还是很陌生。
编辑
这是蜘蛛:
class DatamineSpider(scrapy.Spider):
name = "Datamine"
allowed_domains = ["domain.com"]
start_urls = (
'http://www.example.com/en/search/results/smth/smth/r101/m2108m',
)
def parse(self, response):
for href in response.css('.searchListing_details .search_listing_title .searchListing_title a::attr("href")'):
url = response.urljoin(href.extract())
yield scrapy.Request(url, callback=self.parse_stuff)
next_page = response.css('.pagination .next a::attr("href")')
next_url = response.urljoin(next_page.extract()[0])
yield scrapy.Request(next_url, callback=self.parse)
def parse_stuff(self, response):
item = Item()
item['value'] = float(response.xpath('//*[text()="Price" and not(@class)]/../../div[2]/span/text()').extract()[0].split(' ')[1].replace(',',''))
item['size'] = float(response.xpath('//*[text()="Area" and not(@class)]/../../div[2]/text()').extract()[0].split(' ')[0].replace(',', '.'))
try:
item['yep'] = float(response.xpath('//*[text()="yep" and not(@class)]/../../div[2]/text()').extract()[0])
except IndexError:
print …Run Code Online (Sandbox Code Playgroud)