2016-11-26 82 views
0

我要刮 http://ntry.com/#/scores/named_ladder/main.php的html内容与ScrapyScrapy使用Scrapy和硒的网站

但是,由于该网站的Javascript使用和#,我想我必须使用 SeleniumPython)也。

我想写我自己的代码,但我是编程新手,所以我想我需要帮助;

我想先进入ntry.com,并通过点击锚移动到http://ntry.com/#/scores/named_ladder/main.php称为

<body> 
    <div id="wrap"> 
     <div id="container"> 
      <div id="content"> 
       <a href="/scores/named_ladder/main.php">사다리</a> 
      </div> 
     </div> 
    </div> 
</body> 

,然后我想刮使用Scrapy更改的页面上HTMLS。

我该如何制作一个selenium -blended Scrapy蜘蛛?

+0

的可能的复制[硒与scrapy动态页面(http://stackoverflow.com/questions/17975471/selenium-with-scrapy-for-dynamic-页面) – damienc

回答

0

我安装了Selenium,然后加载了PhantomJS模块,它工作完美。

这里是你可以尝试

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 

class FormSpider(Spider): 
    name = "form" 

    def __init__(self): 

     dcap = dict(DesiredCapabilities.PHANTOMJS) 
     dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36") 

     self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false']) 
     self.driver.set_window_size(1366,768) 


    def parse_page(self, response): 
      self.driver.get(response.url) 
      cookies_list = self.driver.get_cookies() 
+0

你将不得不编写你自己的'start_requests'方法......我跳过了它。 – Umair