I'm trying to scrape some data from https://webcat.schaeffler.com/web/schaeffler/pl/PKW/applicationSearch.xhtml.
I started to build the structure of my application:
require 'nokogiri'
require 'open-uri'
class Scrape
def first(strona)
@page = Nokogiri::HTML(open(strona))
end
def marka(css)
@page.css(css).text
end
end
x = Scrape.new
x.first("https://webcat.schaeffler.com/web/schaeffler/pl/PKW/index.xhtml")
puts x.marka("a#searchByConstraints:form:j_idt491:0:j_idt493:0:j_idt495")
It should put "ABARTH", but id
includes special characters like ":"
and the only thing that I get is:
unexpected '0' after ':' (Nokogiri::CSS::SyntaxError)
I found the solution on "Is there a way to escape non-alphanumeric characters in Nokogiri css?", so I changed the last line in my code to:
puts x.marka('*[id="searchByConstraints:form:j_idt491:0:j_idt493:0:j_idt495"]')
It returns an empty string, but I don't know why.
The element on the target site looks like:
<a id="searchByConstraints:form:j_idt491:0:j_idt493:0:j_idt495" href="/web/schaeffler/pl/PKW/3854/applicationSearch.xhtml" title="ABARTH">ABARTH</a>
I did something wrong or it doesn't work in my case.