0

I am web-scraping the date value inputted in the datepicker below. I have located the HTM of the datepicker. However, It shows no date value and my Python code returns nothing. Am I using a wrong method?

Webpage link: https://rate.amcm.gov.mo/en/financial-information/middle-rates

Target HTML: <input type="text" class="date-picker" id="display-picker">

Target date

My Python code:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep

url = 'https://rate.amcm.gov.mo/en/financial-information/middle-rates'
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
time.sleep(5)
input_date = driver.find_element_by_id('display-picker')
print(input_date.text)
driver.close()
2
  • 1
    Yes, the date value (as rates) is gathered through a post request. Then, some js script fill the HTML input. Look at F12->Network->XHR, and build a post request with the 'requests' package. Commented Aug 20, 2021 at 16:32
  • 1
    Thank you very much! I got the data through XHR successfully. But the date I got is like "1629388800". Do you know how to transform it into a normal format? Commented Aug 20, 2021 at 17:44

1 Answer 1

2

If the date is in this format - 1629388800 then you can convert it to readable format using datetime module.

from datetime import datetime
x = 1629388800
d = datetime.strftime(datetime.fromtimestamp(x), '%d/%m/%Y')
print(d)
19/08/2021
Sign up to request clarification or add additional context in comments.

1 Comment

Thank ce.teuf and Ram, problem solved! For those who need more information, you can refer to here for more about how to get an XHR response.

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.