0
我想從雅虎財經 http://finance.yahoo.com/q/hp?s=^TWII&a=00&b=15&c=2004&d=11&e=4&f=2015&g=mscrapy:如何在空白處輸入參數
我希望程序在啓動一年空白處鍵入「2004」和「2015年」的結束年數據下載空間。我怎樣才能做到這一點?
我的代碼如下所示:
import scrapy
from selenium import webdriver
import time
from scrapy.selector import Selector
from scrapy.selector import HtmlXPathSelector
from taiex.items import taiexItem
import unicodecsv as csv
class taiex_spider(scrapy.Spider):
name = 'taiex_spider'
allowed_domains = ['finance.yahoo.com/']
start_urls = ['http://finance.yahoo.com/q/hp?s=^TWII&a=00&b=15&c=2004&d=11&e=4&f=2015&g=m']
def __init__(self):
self.driver = webdriver.Firefox()
def parse(self, response):
items = []
item = taiexItem()
driver = self.driver
driver.get(response.url)
driver.find_element_by_css_selector('select[id="selstart"]>option[value="00"]').click()
driver.find_element_by_css_selector('select[id="selend"]>option[value="11"]').click()
driver.find_element_by_xpath('//input[@id="monthly"]').click()
driver.find_element_by_xpath('//input[@class="rapid-nf"]').click()
driver.find_element_by_partial_link_text('Download to Spreadsheet').click()
你可以只使用scrapy做到這一切,沒有硒,有即使是他們提供的CSV,您可以下載http://stackoverflow.com/questions/35438381/how-to-import-a-table-with-headings-to-a-data-frame-using-pandas-module/35441264 #35441264。還有一個雅虎json apihttp://stackoverflow.com/a/35541497/2141635 –