Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I locate the tag containing this text?

I am using Open::URI and Nokogiri to scrape a Google search page:

 require 'open-uri'
 require 'nokogiri'
 url = http://www.google.co.uk/search?&q=toys&start=0&num=&complete=0
 doc = Nokogiri::HTML(open(url))
 mas = doc.css('li.g')[7]
 mas.at_css('.mas-row')

From this result I am interested in just one result:

"Amazon.co.uk: Toys - Harry Potter: Toys & Games"

and I would like to get the data from "div class mas-row".

I can not find it. I looked in the "doc" variable and it can not be found. After that I looked for the text that is in that "div" and for the first div a part of the text was found but nothing from the next div.

Can anyone help me with this?

like image 559
John Avatar asked Dec 05 '25 05:12

John


1 Answers

The div with mas-row is included in the HTML. It's rendered by JavaScript.

Use a library that can handle JavaScript, such as selenium.

like image 175
falsetru Avatar answered Dec 06 '25 21:12

falsetru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!