Login using Python 3.5 to SobrusPharma
<p>I'm trying to crawl my erp (SobrusPharma), I tried a whole lot of modules for python 3.5 and nothing works, if only someone can give me the solution for the login part, as for the crawling part it's done.
The login url is : </p>

<p><a href="https://sobruspharma.com/auth/login" rel="nofollow">https://sobruspharma.com/auth/login</a></p>

<p>And the pages to crawl have the following structure:</p>

<p><a href="https://sobruspharma.com/product/63301/table" rel="nofollow">https://sobruspharma.com/product/63301/table</a> (the number changes, that's the dynamic part.</p>

<p>Thank you in advance, I've tried the following modules:</p>

<pre><code>import requests
import urllib.request
import mechanicalSoup
</code></pre>

<p>In need of help here, 
Thanks a lot!</p>

<p>It is pretty straightforward, all you need to parse is the <em>hash</em> from the form:</p>

<pre><code>id="connex_form" 
                            class=" login_form"&gt;                                
&lt;input type="hidden" name="hash"    value="e60f5fef37fe07b0b516d71666071316" id="hash"&gt;     
</code></pre>

<p>which you can find with <em>bs4</em> and post the remaining data:</p>

<pre><code>post = "https://sobruspharma.com/auth/login"
form_data = {"hash": "",
             "email": "foo@bar.com",
             "password": "foo",
             "remember_me": "0",
             "submit": "To log in"}

from bs4 import BeautifulSoup
from requests import Session

with Session() as s:
    soup = BeautifulSoup(s.get("https://sobruspharma.com/auth/login").content)
    hash_ = soup.select_one("#hash")["value"]
    form_data["hash"] = hash_
    login = s.post(post, data=form_data)
</code></pre>

python python-requests python-3.5