0

Suppose I have parsed a line of HTML that is the following...

<a href="http://www.google.com" class="blah"><img src="logo.png" border="0"></img><br><span class="red">Go to google!</span></a>

This is just an example...but how would I go about stripping everything EXCEPT the following:

http://www.google.com
logo.png
Go to google!

Also, is it possible to search for wildcards?

2 Answers 2

1

If you could make use of some gems it will be a very simple job. I would recommend you Mechanize gem. Reference: http://mechanize.rubyforge.org/Mechanize.html

Sign up to request clarification or add additional context in comments.

Comments

1

Maybe like this:

doc = Nokogiri::HTML '<a href="http://www.google.com" class="blah"><img src="logo.png" border="0"></img><br><span class="red">Go to google!</span></a>'
doc.xpath('//*/@href|//*/@src|//*/text()').map(&:to_s)

1 Comment

I'm not sure what you mean by wildcards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.