This is the first test paragraph.
This is the second test paragraph.
END
parser=Hpricot.parse(html_document)
(parser/:p).each do |list_item|
puts list_item.inner_html
end
If you ran this example, you would get these results:
This is the first test paragraph.
This is the second test paragraph.
This example simply divides your Hpricot parser document by :p (parser/:p).
Because Hpricot interprets divide as ???search by,??? it returns an array of all of the p tags. You
then use the inner_html method, which returns the HTML code inside that element, to
print out the contents of each of your test paragraphs. Of course, you can use Hpricot to
search by other tags, and you can perform more complicated searches, such as finding all
of the p tags inside a div of a certain class. You can find out more about using Hpricot at
http://code.
Pages:
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175