不在和服域名列表里_使用和服处理分页,无限滚动和JavaScript

不在和服域名列表里

Back in July 2014, I published the Web Scraper’s guide to Kimono. Being a web scraper myself, I had concluded that YC-funded Kimono had definitely done a commendable job, but I was also critical of its shortcomings — most importantly, the limitations of pagination. I have been closely following the developments at Kimono Labs since.

早在2014年7月,我就发布了Web Scraper的Kimono指南 。 我本人是网络刮板手,我得出的结论是,YC资助的和服无疑做得值得称赞,但我也批评它的缺点-最重要的是,分页的局限性。 从那以后,我一直密切关注和服实验室的发展。

Over the last month in particular, they have released quite a few new features, some of them focussing on the pagination issues I raised in my earlier post. Therefore, I decided to revisit Kimono and look at these new enhancements.

特别是在过去的一个月中,他们发布了许多新功能,其中一些功能集中于我在上一篇文章中提出的分页问题。 因此,我决定重新访问和服并查看这些新增强功能。

JavaScript对API结果的修改 (JavaScript modifications to API results)

The first feature we’re going to look at is the addition of a JavaScript API. It’s recently been added as an experimental feature that lets you modify the results after extracting them through the API you created.

我们要看的第一个功能是添加JavaScript API。 最近,它被添加为实验功能,可让您在通过创建的API提取结果后修改结果。

It has a lot of potential applications. Often, it’s seen that the data that we extract from webpages are not in our desired format and post-processing is required to polish the data. By enabling us to create JavaScript functions that modify the extracted data, Kimono lets us make the process faster by eliminating the need for any fine-tuning of data.

它具有很多潜在的应用。 通常,可以看到我们从网页提取的数据不是我们想要的格式,因此需要后期处理来完善数据。 通过使我们能够创建用于修改提取的数据JavaScript函数,和服使我们能够消除对数据的任何微调,从而使处理过程更快。

To demonstrate such a feature, let’s select the old API we created from the list of APIs available to you after logging into your account. In the Modify Results tab, you can see a text box where you can enter your JavaScript function that will be applied to your results.

为了演示这种功能,让我们在登录帐户后从可用的API列表中选择我们创建的旧API。 在“修改结果”选项卡中,您会看到一个文本框,您可以在其中输入将应用于结果JavaScript函数。

JS modify API

The mini editor that is provided is quite helpful, as it tells you in real time if there are errors in your code. Let us try to append the total number of results

提供的迷你编辑器非常有用,因为它可以实时告诉您代码中是否有错误。 让我们尝试附加结果总数

function transform(data) {    
  var total_count = 0,
    length = data.results.length;

  for (var i = 0; i < length; i++) {
    total_count += data.results[i].length;
  }

  data.totalCount = total_count;

  return data;
}

The best part about this enhancement is that it is not automatically applied on your data every time you call the API. To apply the modify function to the endpoint, you need to modify your API call. For instance, if your API call was the following —

关于此增强功能的最好之处在于,它不会在每次调用API时自动应用于您的数据。 要将修改功能应用于端点,您需要修改您的API调用。 例如,如果您的API调用是以下内容-

https://kimonolabs.com/api/[API_URL]?apikey=[yourAPIkey]

You need to add a GET parameter kimmodify and set it to 1. Your modified URL looks something like this.

您需要添加GET参数kimmodify并将其设置为1 。 修改后的网址如下所示。

https://kimonolabs.com/api/[API_URL]?apikey=[yourAPIkey]&kimmodify=1

Kimono also allows you send custom variables to this function using GET variables. For instance, if you need to send the parameter myVar with the value test, you should modify your URL as follows —

和服还允许您使用GET变量将自定义变量发送到此函数。 例如,如果您需要发送带有值test的参数myVar ,则应按以下方式修改URL:

http://www.kimonolabs.com/apis/<API_ID>/?apikey=<API_KEY>&myVar=test

This variable is available with global scope in your function. It can be accessed as shown below.

该变量在函数中具有全局范围。 可以如下所示进行访问。

query.myVar == 'test'; // true

For a detailed post on the JavaScript API, you may refer to the blog post from Kimono.

有关JavaScript API的详细信息,请参见Kimono博客文章

无限滚动 (Infinite Scroll)

The last time I reviewed Kimono, there was no way it could scrape data off pages with infinite scroll. However, Kimono recently announced a new feature that does exactly that. Let’s see how we can utilize the feature by scraping the Twitter feed of Domino’s India.

我上次查看Kimono时,无法无限滚动地从页面上抓取数据。 但是,和服最近宣布了一项完全可以实现这一目的的新功能 。 让我们看看如何通过刮掉Domino's India的Twitter feed来利用该功能。

When you are creating the API though the interactive Kimonofy bookmarklet, notice the button with the infinity symbol on the panel of buttons on the top right.

通过交互式Kimonofy小书签创建API时,请注意右上角按钮面板上带有无穷大符号的按钮。

Infinite scroll button

If you click on the infinite scroll button, Kimono lets you specify how many items need to be encountered before completion. We’ll go with just 50 items.

如果单击无限滚动按钮,和服可让您指定在完成之前需要遇到多少个项目。 我们将只带50件商品。

Setting infinite scroll options

After saving the API, we run it to see the results.

保存API后,我们运行它以查看结果。

Results of infinite scroll crawl

It looks like the data was extracted perfectly. The addition of the infinite scroll feature is a very significant one, since a large number of websites nowadays use the feature.

看来数据已被完美提取。 无限滚动功能的添加是一项非常重要的功能,因为当今许多网站都在使用该功能。

分页增强 (Enhanced Pagination)

Yet another type of infinite scroll convention is providing a “View More” button to add more results to the page. Thankfully, Kimono has come up with another method to extract data off such websites.

无限滚动约定的另一种类型是提供“查看更多”按钮以向页面添加更多结果。 庆幸的是,和服提出了另一种从此类网站提取数据的方法。

While creating an API, you usually highlight the next page link after selecting the pagination button of Kimono on the top. For enhanced pagination, you need to select the “View More” button that loads new posts.

创建API时,通常在选择顶部和服的分页按钮后,突出显示下一页链接。 为了增强分页功能,您需要选择“查看更多”按钮以加载新帖子。

Set up pagination

After saving the API and running it, the results seem satisfactory as they get off the desired data from the web page.

保存API并运行它后,结果从网页上获得所需数据,结果似乎令人满意。

Pagination results

最后的想法 (Final Thoughts)

Back in July, Kimono was relatively new and the only projects in the Kimono showcase were simple pages which reported the FIFA World Cup scores. It’s definitely come a long way as people use Kimono to manage squads in their fantasy football league teams.

早在7月,和服还是一个相对较新的产品,和服展示区中唯一的项目是简单的页面,上面记录了FIFA世界杯的得分。 当人们使用和服来管理他们的梦幻足球联赛球队时,这肯定走了很长一段路。

Kimono has also been used with MonkeyLearn to perform sentiment analysis with the objective to understand and analyze hotel reviews. Furthermore, the data generated through Kimono has also been used to visualize a year of bike rides.

和服也已与MonkeyLearn一起用于进行情感分析 ,目的是了解和分析酒店评论。 此外,通过和服产生的数据也已用于可视化一年的自行车骑行活动

The bottom line is very clear — with the kind of advancement Kimono has made in the last few months and the way people have reacted to it, it’s definitely the next big thing. The question is, what will you use it for?

底线很明确-和服在过去几个月中取得的进步以及人们对此的React方式,这绝对是下一件大事。 问题是,您将用它做什么?

Have you given Kimono a go? How do you use it?

你和服了吗? 你如何使用它?

翻译自: https://www.sitepoint.com/working-pagination-infinite-scroll-javascript-kimono/

不在和服域名列表里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值