# Help with web forms

**URL:** https://discourse.julialang.org/t/help-with-web-forms/56027
**Category:** New to Julia
**Created:** [February 25, 2021, 4:20pm UTC](https://discourse.julialang.org/t/help-with-web-forms/56027 "2021-02-25T16:20:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [February 25, 2021, 4:20pm UTC](https://discourse.julialang.org/t/help-with-web-forms/56027/1 "2021-02-25T16:20:37Z")

</div>

I’m trying to learn how to do some really simple web stuff, like automatically filling out forms, with Julia and am kind of at loss. I found [this python article](https://dzone.com/articles/how-submit-web-form-python), which has a simple example using DuckDuckGo that I am trying to replicate. The `HTTP.jl` examples mostly cover servers and the POST example is for a REST API, so I’ve only gotten as far as

```julia
using HTTP

url = "https://html.duckduckgo.com/html" # URL for submitting the POST
payload = Dict("q" => "julialang") # name of the search field => the search term
req = HTTP.request("POST", url,... ????) # Proper format here?
results = String(req.body) # Figure out way to extract results

```

As another example, the forms I would like to access are more in the form of web calculators, like [this one](https://www.brewingcalculators.com/celsius-c-to-fahrenheit-f/) for example, where the inputs/outputs are more well-defined. For that calculator (based on the DuckDuckGo one), the parameters would be

```julia
url = "https://www.brewingcalculators.com/celsius-c-to-fahrenheit-f/?" # URL for submitting the POST
payload = Dict("?" => 34) # name of the field => a number

```

So, my first question is, what would be the proper format for the `POST` in these cases? And then, is there a well-defined way to get the results out of the response?

Thanks for any help!

---

<div class="post-metadata">

### Author: ![chris-b1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris-b1/32/14165_2.png) [@chris-b1](https://discourse.julialang.org/u/chris-b1)
#### Post date: [February 25, 2021, 6:06pm UTC](https://discourse.julialang.org/t/help-with-web-forms/56027/2 "2021-02-25T18:06:12Z")

</div>

HTTP.jl could use more docs/examples - but this should work, wrapping your payload in a `HTTP.Form` - from api docs [here](https://juliaweb.github.io/HTTP.jl/dev/public_interface/#Request-body-types)

```julia
using HTTP
payload = Dict("q" => "julialang")
form = HTTP.Form(payload)

resp = HTTP.post("https://html.duckduckgo.com/html", [], form)
html = String(resp.body)

```

In terms of doing something with the results - that’s a project of its own - but could use something like [EzXML.jl](https://github.com/JuliaIO/EzXML.jl) to parse the html and pull out data. Python has some more mature html/xml scraping libraries so could also call out to them with `PyCall.jl`

But here’s a simple example with EzXML, pulling the text out all the h2 tags in the html

```julia
using EzXML
tree = parsehtml(html)
titles = strip.(nodecontent.(findall("//h2", tree)))

25-element Array{SubString{String},1}:
 "The Julia Programming Language"
 "Download Julia"
 "GitHub - JuliaLang/julia: The Julia Programming Language"
 "The Julia Language - Posts | Facebook"
 "The Julia Language (@JuliaLanguage) | Твиттер"

```

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [February 25, 2021, 7:23pm UTC](https://discourse.julialang.org/t/help-with-web-forms/56027/3 "2021-02-25T19:23:39Z")

</div>

Great thanks! I’ll play around with EzXML.

---

<div class="post-metadata">

### Author: ![fyzycyst](https://avatars.discourse-cdn.com/v4/letter/f/5daacb/32.png) [@fyzycyst](https://discourse.julialang.org/u/fyzycyst)
#### Post date: [May 14, 2021, 8:41pm UTC](https://discourse.julialang.org/t/help-with-web-forms/56027/4 "2021-05-14T20:41:43Z")

</div>

Look to Chrome’s developer tools… you can actually record the outgoing POST with your form submission and see the exact format of what is sent (along with the headers). It’s a bit brute force, but you can then lovingly handcraft the header and data portions of the POST request.

That at least gets you a minimum working example to expand from.

---

<div class="post-metadata">

### Author: ![sampope](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sampope](https://discourse.julialang.org/u/sampope)
#### Post date: [May 18, 2021, 11:11pm UTC](https://discourse.julialang.org/t/help-with-web-forms/56027/5 "2021-05-18T23:11:42Z")

</div>

thanks for this example. I understand XPath far better than anything else, and it helped me pull out the href’s from a huge html table:

```julia
for n in findall("//tr/td/a/@href", doc)
  println(nodecontent(n))
end

```
