Skip to content

Commit

Permalink
code 302 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
romjerome authored Apr 20, 2023
1 parent 3e31785 commit bb734fa
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions GeneanetForGramps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ def random_headers():
page = s.get(purl)
if page.status_code == "302":
LOG.debug('Need to log in?')
self.connexion(self.user, self.password)
LOG.info('content %s' % str(page.content))
LOG.info('text %s' % page.text)
LOG.info('type %s' % page.headers['Content-Type'])
Expand Down Expand Up @@ -1472,6 +1473,39 @@ def random_headers():

else:
print(_("We failed to be ok with the server"))

def connexion(self, user, password):
'''
Login and password set for geneanet servers
'''
import requests

headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36' }
r = requests.get("https://www.geneanet.org/connexion/"
,headers=headers
)

pos1 = r.text.find('name="_csrf_token" value="')
pos1 = pos1 + len('name="_csrf_token" value="')
pos2 = r.text.find('"', pos1)
csrf = r.text[pos1:pos2]
cooks = r.cookies
headers.update({'referer':'https://www.geneanet.org/connexion/'})
headers.update({'authority':'www.geneanet.org'})
r = requests.post(
"https://www.geneanet.org/connexion/login_check"
,data={
"_username": user
,"_password": password
,"_submit": ""
,"_remember_me": "1"
,"_csrf_token": csrf
}
,allow_redirects=False
,cookies=cooks
,headers=headers
)
LOG.info(r.text)


def create_grampsp(self):
Expand Down

0 comments on commit bb734fa

Please sign in to comment.