ruby - Regex inside Nokogiri for numbers? -


i have code, , need add regex ahead of "href=" integers:

f = file.open("us.html") doc = nokogiri::html(f)  ans = doc.css('a[href=]')  puts doc 

i tried doing:

ans = doc.css('a[href=\d] 

or:

ans = doc.css('a[href="\d"]) 

but doesn't work. can suggest workaround?

if want use regular expression, believe have manually. cannot done css or xpath selector.

you can iterating through elements , comparing href attribute regular expression. example:

html = %q{ <html>   <a href='1'></a>   <a href='adf'></a> </html> }  doc = nokogiri::html(html) ans = doc.css('a[href]').select{ |e| e['href'] =~ /\d/} #=> <a href="1"></a> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -