I'm trying to get the price data from the Fipe table automatically.
Structurally, the information stays in this location:
library(httr)
library(rvest)
url <- "http://veiculos.fipe.org.br/"
read_html(url) %>%
html_nodes("td")
{xml_nodeset (16)}
[1] <td class="noborder"><p>Mês de referência:</p></td>
[2] <td><p>{mes-de-referencia}</p></td>
[3] <td class="noborder"><p>Código Fipe:</p></td>
[4] <td><p>{codigo-fipe}</p></td>
[5] <td class="noborder"><p>Marca:</p></td>
[6] <td><p>{marca}</p></td>
[7] <td class="noborder"><p>Modelo:</p></td>
[8] <td><p>{modelo}</p></td>
[9] <td class="noborder"><p>Ano Modelo:</p></td>
[10] <td><p>{ano-modelo}</p></td>
[11] <td class="noborder"><p>Autenticação</p></td>
[12] <td><p>{autenticacao}</p></td>
[13] <td class="noborder"><p>Data da consulta</p></td>
[14] <td><p>{data-consulta}</p></td>
[15] <td class="noborder"><p>Preço Médio</p></td>
[16] <td><p>{preco-medio}</p></td>
The information is empty (as in '{mes-reference}') because a POST request with the desired vehicle data is required.
The data required for POST are indicated in the print below.
ItriedtodoPOSTonthepagebutreturnedStatus405.
POST(url,body=list(codigoTabelaReferencia="215",
codigoMarca = "2",
codigoModelo = "4564",
codigoTipoVeiculo = "1",
anoModelo = "2015",
codigoTipoCombustivel = "3",
tipoVeiculo = "carro",
modeloCodigoExterno = "",
tipoConsulta = "tradicional"
)
)
Response [http://veiculos.fipe.org.br/]
Date: 2017-07-16 17:16
Status: 405
Content-Type: text/html
Size: 1.29 kB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>405 - HTTP verb used to access this page is not allowed.</title>
<style type="text/css">
<!--
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;}
h1{font-size:2.4em;margin:0;color:#FFF;}
...
Is something missing from POST for it to be valid?
Hugs to all