我正在尋求廢除here 中的HTML表格數據,並使用Python和selenium,xlrd,xlwt,urllib2模塊將該數據存儲到Excel工作表中。真正的問題是在將某些細節填充到重定向頁面的某些細節之後,並將該URL放入urllib.open()
函數中,但將表格信息顯示爲空。使用Selinium和Python在Excel工作表中刮掉HTML表格數據
import os,requests,time,xlrd,xlwt
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
browser=webdriver.Firefox()
browser.get("http://www.moneycontrol.com/stocks/histstock.php")
browser.maximize_window()
browser.find_element_by_link_text("INDEX").click()
index_list=["--Index--","S&P BSE Sensex","CNX Nifty","S&P BSE Smallcap","S&P BSE Midcap","S&P BSE 100","S&P BSE 200","S&P BSE 200","S&P BSE BANKEX","S&P BSE Capital Goods","S&P BSE Capital Goods","S&P BSE Metals","S&P BSE IT","S&P BSE Auto","S&P BSE Healthcare","S&P BSE Healthcare","S&P BSE Realty","S&P BSE TECk","S&P BSE PSU","S&P BSE Consumer Durables","S&P BSE Consumer Durables","S&P BSE SHARIAH","S&P BSE IPO","CNX Midcap Index -NSE","CNX Nifty Junior","CNX DEFTY","Nifty Midcap 50","CNX 100","CNX 500","Bank Nifty","CNX IT","CNX REALTY","CNX INFRA","CNX INFRA","CNX FMCG","CNX FMCG","CNX PHARMA","CNX PSE","CNX PSU BANK","CNX SERVICE","CNX SERVICE","CNX SERVICE","CNX SERVICE","CNX SERVICE"]
frm_day=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]
frm_mnth=["Jan","Feb","Mar","Apr","May","June","July","Aug","Sep","Oct","Nov","Dec"]
frm_year=[2015,2014,2013,2012,2011,2010,2009,2008,2007,2006,2005,2004,2003,2002,2001,2000]
for i in frm_day:
"""browser.find_element_by_xpath(".//*[@id='indian_indices']/option[3]")"""
select_indices=browser.find_element_by_name("indian_indices").send_keys(index_list[i+1])
link=browser.find_element_by_name("frm_dy").send_keys(frm_day[i+1])
browser.find_element_by_name("frm_mth").send_keys(frm_mnth[i+1])
browser.find_element_by_name("frm_yr").send_keys(frm_year[i+1])
browser.find_element_by_name("to_dy").send_keys(frm_day[i])
browser.find_element_by_name("to_mth").send_keys(frm_mnth[i])
browser.find_element_by_name("to_yr").send_keys(frm_year[i])
browser.find_element_by_xpath("html/body/center[2]/div/div/div[5]/div[4]/div[2]/div[6]/table/tbody/tr/td[1]/form/div[4]/input[1]").click()
break
執行頁面重定向到otherpage.from該網頁,我需要表的數據的代碼之後,這可能嗎?
通過這樣做,該表顯示爲空。 – ShivaGuntuku
得到了答案。 – ShivaGuntuku