I need to curl | grep some data from a webpage but after setting language to English. In a browser, I can do this by clicking on a link.
I first get the SelectCulture page and save the cookie in a file, then I use it to get the page I need:
#!/bin/bash
#tmp_file="$(mktemp)"
tmp_file="cookies"
curl -s \
--location \
--cookie "$tmp_file" \
--cookie-jar "$tmp_file" \
--user-agent Mozilla/4.0 \
--data-urlencode "ReturnUrl=http://it.bca-europe.com/Default.aspx" \
"http://it.bca-europe.com/Home/SelectCulture/en-GB-BDIT" | egrep "Ospite|Guest"
curl -s \
--location \
--cookie "$tmp_file" \
--user-agent Mozilla/4.0 \
"http://it.bca-europe.com/Default.aspx" | egrep "Ospite|Guest"
The problem is that on first run, when the cookies file does not exist yet, somehow the language doesn't change (you get italian Ospite instead of Guest), whereas the script works from the second run.
This, for example, avoids the need to use a temporary file instead of a static file. Moreover, weirdly, I can't get it to work in a single run.
Any advice?
curlcall need the--cookieand the--cookie-jar? From what I gather, the first call should fill the jar but it should not need (an empty?) cookie at all. I think this could be the culprit, i.e. why it works the second time (since the jar is non-emtpy)...maybe. – sr_ Mar 14 '12 at 9:44