我正在为Github的存储库数据构建一个Web scraper,并在本地数据库中存储特定的repo属性。我目前遇到的问题是将数据拉出超过一页(100条记录)的限制。
这是我的api调用和方法来提取适当的数据:
require 'active_interaction'
require 'json'
class GitHubGet < ActiveInteraction::Base
def execute
response = HTTParty.get(process_path)
# extract_github_data(response)
end
def extract_github_data(response)
parsed_response = JSON.parse(response.body)
result = []
parsed_response["items"].each do |item|
if item["updated_at"] > 1.day.ago
result << {
name: item["name"],
owner: item["owner"]["login"],
url: item["url"],
stars: item["stargazers_count"]
}
end
end
puts result
end
private
def process_path
"https://api.github.com/search/repositories?q=license:mit+license:apache-2.0+license:gpl+license:lgpl+stars:1..2000+fork:false&per_page=100"
end
end
任何有关如何提取多页数据的帮助将不胜感激!谢谢!
响应对象中的标题具有一个键链接,其中包含下一页的URL。