Problem with Parsing 'op.gg'

26 views
Skip to first unread message

ehd...@likelion.org

unread,
May 21, 2017, 1:19:34 PM5/21/17
to nokogiri-talk
{require 'open-uri'
require 'nokogiri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

class Opgg < ApplicationRecord
url = "https://www.op.gg/statistics/champion/"
#Nokogiri::HTML::ParseOptions::NOBLANKS
data = Nokogiri::HTML(open(url), nil, 'UTF-8')


@opggs = data.css('div#ChampionStatsTable')

@opggs.each do |opgg|
Opgg.create(
:cname => opgg.css('table tr td').text.strip,
:rate => opgg.css('table tr td.Cell').text.strip,
:gnum => opgg.css('table tr td.Cell').text.strip,
:kda => opgg.css('table tr td span.Ratio').text.strip,
:cs => opgg.css('table tr td.Cell span').text.strip,
:gold => opgg.css('table tr td.Cell span').text.strip
)
end
end}

I'm practicing parsing with nokogiri, and trying to parse 'op.gg/' site. But i can't get results i want. What's problem with my code?

Dan Corrigan

unread,
May 23, 2017, 12:01:29 PM5/23/17
to nokogiri-talk
Hi,

I don't think this is a Nokogiri problem. I took a quick look at the page you're trying to get data from, and the page is loading the table content via Ajax. You should probably try "https://www.op.gg/statistics/ajax2/champion/" as your URL instead. That's where it's loading the table content from.

Best,
Dan
Reply all
Reply to author
Forward
0 new messages