[英]How to scrape all the data from a page using Selenium?
I can not click the button of the days. 我无法单击日期按钮。
from selenium import webdriver
browser = webdriver.Chrome()
url = "http://rate.am/en/armenian-dram-exchange-rates/banks/non-cash"
browser.get(url)
from selenium import *
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from time import*
After importing all necessary tools I have tried to write code which will go to the page, click to the historical data and go by dates, but I have problem with clicking on the days buttons 导入所有必需的工具之后,我尝试编写将转到页面,单击历史数据并按日期排序的代码,但是单击“天”按钮时出现问题
browser = webdriver.Chrome()
url = "http://rate.am/en/armenian-dram-exchange-rates/banks/non-cash"
browser.get(url)
all_data=browser.find_element_by_xpath('//*[@id="aspnetForm"]/div[3]/div[2]/div[1]/div[4]/div[3]/table/tbody/tr/td[1]/a')
all_data.click()
years=browser.find_element_by_xpath('//*[@id="calBorder"]/span/table/tbody/tr[1]/td/table/tbody/tr/td[2]/select')
for i in range(len(years.find_elements_by_tag_name('option'))):
for j in range(12):
for z in range(31):
time=browser.find_element_by_xpath('//*[@id="ctl00_Content_RB_dtpick1_dpHours"]')
for x in range(len(time.find_elements_by_tag_name('option'))):
all_data=browser.find_element_by_xpath('//*[@id="aspnetForm"]/div[3]/div[2]/div[1]/div[4]/div[3]/table/tbody/tr/td[1]/a')
all_data.click()
sleep(0.3)
yearss = browser.find_element_by_xpath('//*[@id="calBorder"]/span/table/tbody/tr[1]/td/table/tbody/tr/td[2]/select')
sy = Select(yearss)
sy.select_by_index(i)
sleep(0.3)
months = browser.find_element_by_xpath('//*[@id="calBorder"]/span/table/tbody/tr[1]/td/table/tbody/tr/td[1]/select')
sm = Select(months)
sm.select_by_index(j)
sleep(0.3)
days=browser.find_element_by_xpath('//*[@id="calBorder"]/span/table/tbody/tr[3]/td/table/tbody/tr[2]/td[6]')
if 'bgcolor="white"'==None in days:
days.click()
sleep(0.3)
times=browser.find_element_by_xpath('//*[@id="ctl00_Content_RB_dtpick1_dpHours"]')
ti=Select(times)
ti.select_by_index(x)
sleep(0.3)
show=browser.find_element_by_xpath('//*[@id="ctl00_Content_RB_dtpick1_btnOk"]')
show.click()
sleep(0.3)
I haven't handled the year but the pattern would be the same. 我没有处理年份,但是模式将是相同的。 As far as selecting days is concerned I created an xpath that would identify all of the
td
elements and then select those whose text was equal to a given date, namely 23, which was just a random choice on my part. 就选择日期而言,我创建了一个xpath,它将标识所有
td
元素,然后选择文本等于给定日期(即23)的那些元素,这对我来说只是一个随机选择。
>>> from selenium import webdriver
>>> browser = webdriver.Chrome()
>>> url = 'http://rate.am/en/armenian-dram-exchange-rates/banks/non-cash'
>>> browser.get(url)
>>> browser.find_element_by_xpath('.//a[@class="date-picker"]').click()
>>> browser.find_element_by_xpath('.//select[@name="MonthSelector"]').click()
>>> browser.find_element_by_xpath('.//select[@name="MonthSelector"]/option[1]').click()
>>> browser.find_elements_by_xpath('.//td[@class="calTD"]')
>>> browser.find_elements_by_xpath('.//td[@class="calTD" and text()="23"]')[0].click()
>>> browser.find_element_by_xpath('.//input[@id="ctl00_Content_RB_dtpick1_btnOk"]').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.