2017-07-30 5 views
1

Chaque lundi, j'ai besoin d'analyser les dernières semaines (5 jours) "USD 1100". Donc, pour cela, je dois sélectionner la date pour chaque jour de la semaine dernière et "USD 1100" de la série déroulante. Je n'ai besoin que d'un an de taux de ténor. Donc, la réponse finale devrait avoir 5 valeurs de 1 an ténor de "USD RATES 1100".url analyse (webparsing) en python

https://www.theice.com/marketdata/reports/180

from selenium import webdriver 
chrome_path = r"C:\Users\vick\Desktop\python_1\chromedriver.exe" 
driver = webdriver.Chrome(chrome_path) 
driver.get("https://www.theice.com/marketdata/reports/180") 
driver.find_element_by_xpath() 
+0

Pouvez-vous nous montrer un code que vous avez essayé? –

+0

Pour obtenir xpath en chrome, tout ce que vous avez à faire est d'inspecter, faites un clic droit sur l'élément, sélectionnez copier, puis par xpath –

+0

J'ai renvoyé le code (ajouté en question) qui est très basique. Je ne reçois rien dans xpath par lequel je peux analyser toutes les valeurs requises – ads

Répondre

0
from selenium import webdriver 
chrome_path = r"C:\Users\vick\Desktop\python_1\chromedriver.exe" 
driver = webdriver.Chrome(chrome_path) 
driver.get("https://www.theice.com/marketdata/reports/180") 
try: 
    driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div/div[2]/button').click() 
except: 
    pass 

driver.find_element_by_xpath('//*[@id="seriesNameAndRunCode_chosen"]/a/span').click() 
driver.find_element_by_xpath('//*[@id="seriesNameAndRunCode_chosen"]/div/ul/li[5]').click() 
driver.find_element_by_xpath('//*[@id="reportDate"]').clear() 
driver.find_element_by_xpath('//*[@id="reportDate"]').send_keys("27-Jul-2017") #or whatever date 
driver.find_element_by_xpath('//*[@id="selectForm"]/input').click() 
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)/2;") 
print (driver.find_element_by_xpath('//*[@id="report-content"]/div/div/table/tbody/tr[1]/td[2]').get_attribute('innerHTML')) 

Cela permet de sélectionner USD RATES 1100, entrez une date, et soumettre. Vous pouvez boucler ce processus pour entrer plus de dates.

+0

Juste édité pour accepter le bouton –

+0

Monsieur, merci beaucoup pour la réponse. Mais pour moi, au lieu de "USD RATS 1100", il donne encore "EUR RATES 110" – ads

+0

Trouvé le bug, va corriger –

0

réponse finale:

from selenium import webdriver 
chrome_path = r"C:\Users\vick\Desktop\python_1\chromedriver.exe" 
driver = webdriver.Chrome(chrome_path) 
driver.get("https://www.theice.com/marketdata/reports/180") 
try: 
    driver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/div/ 
    div[2]/button').click() 
except: 
     pass 

driver.find_element_by_xpath('//* 
[@id="seriesNameAndRunCode_chosen"]/a/span').click() 
driver.find_element_by_xpath('//* 
[@id="seriesNameAndRunCode_chosen"]/div/ul/li[5]').click() 
driver.find_element_by_xpath('//*[@id="reportDate"]').clear() 
driver.find_element_by_xpath('//*[@id="reportDate"]').send_keys("27-Jul- 
2017") #or whatever date 
driver.find_element_by_xpath('//*[@id="selectForm"]/input').click() 
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)/2;") 
time.sleep(4) 
print ((driver.find_element_by_xpath('//*[@id="report- 
content"]/div/div/table/tbody/tr[1]/td[2]').get_attribute('innerHTML')). 
strip())