Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google自定义搜索API和Ruby_Ruby_Google Api - Fatal编程技术网

Google自定义搜索API和Ruby

Google自定义搜索API和Ruby,ruby,google-api,Ruby,Google Api,我想写一个谷歌搜索刮刀/解析器,从谷歌的linkedin.com索引中提取员工。Linkedin关闭了他们的API,所以我先写了一个Mechanize/Nokogiri刮板,这让我得到了验证码,所以我用谷歌搜索API gem重写了脚本 问题是,我不知道从哪里开始让它带来比第一页更多的结果,官方文件甚至不能被描述为“稀疏” 这是仅返回第1页的代码: require 'rubygems' require 'google/api_client' require 'json' require 'pp'

我想写一个谷歌搜索刮刀/解析器,从谷歌的linkedin.com索引中提取员工。Linkedin关闭了他们的API,所以我先写了一个Mechanize/Nokogiri刮板,这让我得到了验证码,所以我用谷歌搜索API gem重写了脚本

问题是,我不知道从哪里开始让它带来比第一页更多的结果,官方文件甚至不能被描述为“稀疏”

这是仅返回第1页的代码:

require 'rubygems'
require 'google/api_client'
require 'json'
require 'pp'
puts "What organisation's employees shall we get today?"
organisation = gets.chomp
puts "Harvesting Google Search Results - This may take some time"

apikey = "1234"
cxid = "5678"
client = Google::APIClient.new(:key => apikey, :authorization => nil,          :application_name => "linkedout", :application_version => "beta_0.5")
  search = client.discovered_api('customsearch')
  response = client.execute(
 :api_method => search.cse.list,
 :parameters => {
   'q' => 'current ' + organisation + ' site:linkedin.com',
   'maxResults' => 100,
   'key' => apikey,
   'cx' => cxid
   }
)

status, headers, body = response
jsonresponse = response.body

employees = []
@tags = JSON.parse(jsonresponse)['items']
  @tags.each do |tag|
     x = tag['title']
     x.gsub!(/ \| LinkedIn/, "")
     x.downcase!
     x.gsub!(/ profiles/, "")
        employees << x
       end
    employees = employees.uniq
    puts employees

根据,当有其他结果时,应该在项目旁边返回nextPage值。但是它总是说注意:这个API只返回前100个结果。因此,看起来您已经获得了最大数量的结果。

您正在运行哪个版本的Ruby?1.9+的任何版本都会自动要求RubyGems,因此不再需要“RubyGems”。与其期望我们收集JSON示例,不如展示一个简单的输入JSON示例。帮我们帮你,对不起,锡人!你完全正确。我忽略了JSON,因为JSON已经被解析了,所以我愚蠢地假设它与分页无关!你说你只得到第一页结果是什么意思?JSON没有页面。你得到了多少结果?它只返回谷歌搜索第1页的JSON。仅此而已。据我所知,是谷歌API控制着这一切。结果的数量因您进入的组织而异,但通常为6-7名员工。谢谢您的回答!,我错过了这一点,并假设它是100个结果,每页与标准浏览器:回到刮削与机械化它是!
"items": [
  {
   "kind": "customsearch#result",
   "title": "Tina Minor - Recruiter, The Walt Disney Company | LinkedIn",
   "htmlTitle": "Tina Minor - Recruiter, The \u003cb\u003eWalt     Disney\u003c/b\u003e Company | LinkedIn",
   "link": "https://www.linkedin.com/pub/tina-minor-recruiter-the-walt-disney-    company/5/849/5a6",
   "displayLink": "www.linkedin.com",
   "snippet": "View Tina Minor - Recruiter, The Walt Disney Company's     professional profile on \n... Current. The Walt Disney Company. Previous. True     Religion Brand Jeans, ...",
   "htmlSnippet": "View Tina Minor - Recruiter, The \u003cb\u003eWalt     Disney\u003c/b\u003e Company&#39;s professional profile on \u003cbr\u003e\n...     \u003cb\u003eCurrent\u003c/b\u003e. The \u003cb\u003eWalt Disney\u003c/b\u003e     Company. Previous. True Religion Brand Jeans,&nbsp;...",
   "formattedUrl": "https://www.linkedin.com/pub/tina-minor-recruiter-the-    walt-   disney.../5a6",
       "htmlFormattedUrl": "https://www.linkedin.com/pub/tina-minor-recruiter-    the-       \u003cb\u003ewalt\u003c/b\u003e-    \u003cb\u003edisney\u003c/b\u003e.../5a6",
       "pagemap": {
        "cse_image": [
         {
           "src":          "https://media.licdn.com/mpr/mpr/shrink_200_200/p/8/005/09b/3f2/1eb6f83.jpg"
      }
    ],
    "person": [
     {
      "location": "Greater Los Angeles Area",
      "role": "Recruiter, Talent Acquisition at The Walt Disney Company"
     }
    ],
    "cse_thumbnail": [
     {
      "width": "160",
      "height": "160",
      "src": "https://encrypted-tbn1.gstatic.com/images?    q=tbn:ANd9GcTbmlbDVBOMKTtOA_D88aFaPuZ9MjABABwumzBPk0F2x2P2-0puaIRlktce"
     }
    ],
    "metatags": [
     {
      "globaltrackingurl": "//www.linkedin.com/mob/tracking",
      "globaltrackingappname": "profile",
      "globaltrackingappid": "webTracking",
      "lnkd-track-json-lib": "https://static.licdn.com/scds/concat/common/js?    h=2jds9coeh4w78ed9wblscv68v-ebbt2vixcc5qz0otts5io08xv&fc=2",
      "treeid": "SnQhTqcr1RNgnKS8RSsAAA==",
      "appname": "profile",
      "pageimpressionid": "29ca4803-0233-4934-955a-1959a37dfbbf",
      "pagekey": "nprofile_v2_public_fs",
      "analyticsurl": "/analytics/noauthtracker",
      "msapplication-tileimage":     "https://static.licdn.com/scds/common/u/images/logos/linkedin/logo-in-win8-tile-    144_v1.png",
      "msapplication-tilecolor": "#0077B5",
      "application-name": "LinkedIn",
      "remote-nav-init-marker": "true"
     }
    ],
    "hcard": [
     {
      "fn": "Tina Minor - Recruiter, The Walt Disney Company",
      "title": "Recruiter, Talent Acquisition at The Walt Disney Company"
     }
    ]
   }
  }
  ...