0

im trying to scrape table based on dates from this site https://www.bi.go.id/id/statistik/informasi-kurs/transaksi-bi/Default.aspx with this code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import re
import time
from bs4 import BeautifulSoup
# Import webdriver to initialise a browser
from selenium.webdriver import ActionChains
import csv
import pandas as pd
import requests
driver = webdriver.Chrome()
driver.get("https://www.bi.go.id/id/statistik/informasi-kurs/transaksi-bi/Default.aspx")

wait = WebDriverWait(driver, 10)

# click "usd"



book = wait.until(
    EC.element_to_be_clickable((By.XPATH,' //*[@id="selectPeriod"]/option[range]'))
)
book.click()

book1 = wait.until(
    EC.element_to_be_clickable((By.XPATH,' //*[@id="ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_ddlmatauang1"]/option[USD]'))
)
book1.click()



start_date = driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_txtFrom")
start_date.send_keys("20-Nov-15")
end_date = driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_txtTo")
end_date.send_keys("20-Nov-20")
submit_button = driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_btnSearch1").click()

but instead i got this error and i dont know why.can anybody help me what goes wrong?

--------------------------------------------------------------------------- TimeoutException Traceback (most recent call last) in 9 10 ---> 11 book = wait.until( 12 EC.element_to_be_clickable((By.XPATH,' //*[@id="selectPeriod"]/option[range]')) 13 )

~\anaconda3\lib\site-packages\selenium\webdriver\support\wait.py in until(self, method, message) 78 if time.time() > end_time: 79 break ---> 80 raise TimeoutException(message, screen, stacktrace) 81 82 def until_not(self, method, message=''):

TimeoutException: Message:

4
  • "Selenium will wait for a maximum of 10 seconds for an element matching the given criteria to be found. If no element is found in that time, a TimeoutException is thrown." Try increasing the wait, or make sure the xpath is correct? Commented Jan 15, 2021 at 2:02
  • hm the results still same..and the xpath im sure its right tho.. Commented Jan 15, 2021 at 2:11
  • I've never used an option in a wait for clickable, so I'm not sure if it would work or you need to separate it and click it separately Commented Jan 15, 2021 at 2:17
  • If the results are still the same I recommend trying to go through website's html, and try and piece together how you can get there manually by navigating with BeautifulSoup once you use get page source. That's how I used to do it. It does take quite a while to figure out the structure, before you can automate the process in a for loop. Commented Jan 15, 2021 at 2:21

1 Answer 1

0

This should work since it's a Select tag.

driver.get("https://www.bi.go.id/id/statistik/informasi-kurs/transaksi-bi/Default.aspx")
wait = WebDriverWait(driver, 10)
book = wait.until(EC.element_to_be_clickable((By.ID,"selectPeriod")))
sel = Select(book)
sel.select_by_value("range")

Import

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.select import Select
Sign up to request clarification or add additional context in comments.

2 Comments

thank you ! but i got 1 more problem,the submit button wont work! submit_button=driver.find_element_by_id("ctl00_PlaceHolderMain_g_6c89d4ad_107f_437d_bd54_8fda17b556bf_ctl00_btnSearch1").click() can you help me?
The id seems dynamic which means it'll change.//input[@value='Search'] Use the following xpath instead.

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.