简体   繁体   English

如何使用Selenium抓取页面中的所有数据?

[英]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.

相关问题 如何使用 Selenium 和 Python 从 Linkedin 页面抓取嵌套数据 - How to scrape the nested data from Linkedin page using Selenium and Python 如何使用 selenium 从网站抓取数据 - How to scrape data from website using selenium 使用 Selenium 从 .jsp 页面抓取表格数据 - Scrape table data from .jsp page using Selenium Python 使用 Selenium 从页面上的多个链接中抓取数据 - Python Using Selenium to scrape data from multiple links on a page 使用 selenium 将所有列中的数据刮入 python 以加载更多 - Scrape data from all columns into python using selenium to load more 如何使用 python selenium 从速卖通的每个产品页面抓取数据 - How to scrape data from each product page from Aliexpress using python selenium 如何使用 python/beautifulsoup/selenium 抓取弹出窗口中的所有数据? - How to scrape all data in the pop windows using python/beautifulsoup/selenium? 如何单击下一步按钮以使用 selenium python 从所有页面抓取数据? - How to click on next button to scrape data from all pages using selenium python? 如何使用beautifulsoup从页面中抓取数据 - How to scrape data from page using beautifulsoup 如何使用 Selenium 从 LinkedIn 公司页面中抓取员工数量? - How to scrape employee counts from a LinkedIn company page using Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM