Selenium + PhantomJS in Scrapy



我正在尝试使用硒和phantomjs获取网站的动态内容。这是我的代码

class judge(Spider):
    name = "judge"
    start_urls = ["http://wenshu.court.gov.cn/List/List?sorttype=1&conditions=searchWord+2+AJLX++%E6%A1%88%E4%BB%B6%E7%B1%BB%E5%9E%8B:%E6%B0%91%E4%BA%8B%E6%A1%88%E4%BB%B6"]
    def init_driver(self):
        driver = webdriver.Chrome()
        return driver 
    def parse(self,response):
        driver = self.init_driver()
        driver.get(self.start_urls[0])
        sel = Selector(text=driver.page_source)
        self.logger.info(u'---------------Parsing----------------')
        print sel.xpath("//div[@class='dataItem'][1]/table/tbody/tr[1]/td/div[@class='wstitle']/a/text()").extract()
        self.logger.info(u'---------------success----------------')

当我使用driver = webdriver.Chrome()尝试脚本时,SEL.XPATH("//Div [@class ='dataitem']给出了所需的内容,并且一切正常。但是,当我使用driver = webdriver.PhantomJS(),SEL.XPATH("//)div [@class ='dataitem']是空的。我尝试在driver.get()之后使用WebDriverWait使页面充满加载,但不起作用。

您可以尝试以下方法:

driver = webdriver.PhantomJS('add your directory of phantomjs here')

最新更新