0

I am trying to change the checkin and checkout date in the following url: https://www.booking.com/hotel/fr/le-leman.fr.html?label=gen173nr-1DCAEoggI46AdIM1gEaCyIAQGYAQ24ARjIAQzYAQPoAQGIAgGoAgS4AuGugoYGwAIB0gIkODQyNzI0MzUtNzlmZi00ZTY1LWJkNGUtZmQyMGIxMGE3NzJl2AIE4AIB;sid=1a1526834c348b388f7097913631c2e3;checkin=2021-06-09;checkout=2021-06-10;sig=v11C1wtOKO

I thought about using a Regex rule to set today's date:

d = datetime.date.fromordinal(datetime.date.today().toordinal()-0).strftime("%m/%d/%Y")
url = driver.current_url
regex = r"^\d{4}\-(0?[1-9]|1[012])\-(0?[1-9]|[12][0-9]|3[01])$"
result = re.sub(regex, d, url, 0)
if result:
    print (result)

But it's doesen't work.

Thank's you for your attention.

PS : SORRY I have a bad english..

2 Answers 2

0

You don't need regex for this, you can simply try this:

import datetime

checkin_date = datetime.date.fromordinal(datetime.date.today().toordinal()-0).strftime("%Y-%m-%d")
checkout_date = datetime.date.fromordinal(datetime.date.today().toordinal()-0).strftime("%Y-%m-%d")
url = "https://www.booking.com/hotel/fr/le-leman.fr.html?label=gen173nr-1DCAEoggI46AdIM1gEaCyIAQGYAQ24ARjIAQzYAQPoAQGIAgGoAgS4AuGugoYGwAIB0gIkODQyNzI0MzUtNzlmZi00ZTY1LWJkNGUtZmQyMGIxMGE3NzJl2AIE4AIB;sid=1a1526834c348b388f7097913631c2e3;checkin="+checkin_date+";checkout="+checkout_date+";sig=v11C1wtOKO"
print(url)

And u can give the variables checkin_date and checkout_date the value you want and then use the url simply.

Sign up to request clarification or add additional context in comments.

Comments

0

Very HelpFull I try something else and still working well.

    # Selectionne la date d'aujourd'hui au format compatible booking
d = datetime.date.fromordinal(datetime.date.today().toordinal()+1).strftime("%Y-%m-%d")
# Selectionne la date d'aujourd'hui +n au format compatible booking
d1 = datetime.date.fromordinal(datetime.date.today().toordinal()+2).strftime("%Y-%m-%d")
# Variable pour préparer le changement sur booking
dformat = 'checkin=' + d
d1format = 'checkout=' + d1
# Selectionne l'url actuelle
url = driver.current_url
#Remplace le text de la date par la nouvelle
url = url.replace("checkin=2021-06-02", dformat)
url = url.replace("checkout=2021-06-03", d1format)
driver.get(url)

it also works, it's a little worse than yours but it's functional;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.