To get a response, you can either use [[Rex::Proto::Http::Client|How to send an HTTP request using Rex Proto Http Client]], or the [[HttpClient|How to Send an HTTP Request Using HttpClient]] mixin to make an HTTP request. If you are writing a module, you should use the mixin.
However, in this documentation we are only focusing on ```res.body```.
## Choosing the right parser
Format | Parser
------ | ------
HTML | Nokogiri
XML | Nokogiri
JSON | JSON
If the format you need to parse isn't on the list, then fall back to ```res.body```.
## Parsing HTML with Nokogiri
When you have a Rex::Proto::Http::Response with HTML in it, the method to call is:
```ruby
html = res.get_html_document
```
This will give you a Nokogiri::HTML::Document, which allows you use the Nokogiri API.
There are two common methods in Nokogiri to find elements: #at and #search. The main difference is that the #at method will only return the first result, while the #search will return all found results (in an array).
Consider the following example as your HTML response:
```html
<html>
<head>
<title>Hello, World!</title>
</head>
<body>
<div class="greetings">
<div id="english">Hello</div>
<div id="spanish">Hola</div>
<div id="french">Bonjour</div>
</div>
</body>
<html>
```
**Basic usage of #at**
If the #at method is used to find a DIV element:
```ruby
html = res.get_html_document
greeting = html.at('div')
```
Then the ```greeting``` variable should be a Nokogiri::XML::Element object that gives us this block of HTML (again, because the #at method only returns the first result):
```html
<div class="greetings">
<div id="english">Hello</div>
<div id="spanish">Hola</div>
<div id="french">Bonjour</div>
</div>
```
**Grabbing an element from a specific element tree**
```ruby
html = res.get_html_document
greeting = html.at('div//div')
```
Then the ```greeting``` variable should give us this block of HTML:
```html
<div id="english">Hello</div>
```
**Grabbing an element with a specific attribute**
Let's say I don't want the English Hello, I want the Spanish one. Then we can do: