How to get a uuid with python requests
<p>I am attempting to log into a web page using the python requests module but the Post data on the website that I want to log into includes a uuid tag.</p>

<pre><code>pass: ********
user: ********
uuid: ********
</code></pre>

<p>I have thoroughly searched for any mention of this anywhere in most requests documentation. Is this simply out of the capabilities of the program or is it something that I am overlooking.</p>

<p>This is the code I am using.</p>

<pre><code>import requests

url = 'www.website.com'

with requests.Session() as c:
     c.get(url)
     values = {'pass': 'passsword', 'user': 'username'}
     response = c.post(url, data=values)
     print response
</code></pre>

<p>You can parse it from the source:</p>

<pre><code>In [29]: from bs4 import BeautifulSoup

In [30]: import re

In [31]: patt = re.compile("document.cplogin.uuid.value=\"(.*?)\"")

In [32]: with requests.Session() as s:
   ....:         page = s.get('http://myneu.neu.edu/cp/home/displaylogin').content
   ....:         soup = BeautifulSoup(page, "html.parser")
   ....:         script = soup.find("script", language="javascript1.1")
   ....:         uuid = patt.search(script.text).group(1)
   ....:     

In [33]: uuid
Out[33]: u'ff3e7ddd-0823-4f44-a003-0e68a9321e08'
</code></pre>

<p>If you look at the source of the login page, inside the script with the attribute <em>language="javascript1.1"</em>, you can see the uuid:</p>

<pre><code>function login()
{
    setQueryAsCookie();
    document.cplogin.user.value=document.userid.user.value;
    document.cplogin.uuid.value="21fbc26a-3a3d-4802-ba4a-39a40aad881c";
    document.cplogin.submit();
}
</code></pre>

<p>So just pass that along with the rest of the form data when you post.</p>

<p>The post url also seems to be <em><a href="https://myneu.neu.edu/cp/home/login" rel="nofollow">https://myneu.neu.edu/cp/home/login</a></em>, so:</p>

<pre><code>from bs4 import BeautifulSoup
import re

patt = re.compile("document.cplogin.uuid.value=\"(.*?)\"")
data = {"user":"uname", "pass":"passw"}
post = "https://myneu.neu.edu/cp/home/login"

with requests.Session() as s:
    page = s.get('http://myneu.neu.edu/cp/home/displaylogin')
    soup = BeautifulSoup(page.content, "html.parser")
    script = soup.find("script", language="javascript1.1")
    uuid = patt.search(script.text).group(1)
    data["uuid"] = uuid
    resp = s.post(post, data=data)
</code></pre>

python http post login python-requests