如何在已经scrapy下载的网页上使用selenium.PhantomJS()

时间:2014-07-29 10:28:44

标签: python selenium scrapy phantomjs

def parseList(self, response):
    dr=webdriver.PhantomJS()   
    dr.get(response.url)
    pageSource = dr.page_source
    print dr.page_source

该网页已经通过scrapy下载(包含在response.body中),dr.get(response.url)将再次下载。

有没有办法让selenium直接使用response.body

2 个答案:

答案 0 :(得分:1)

如何使用response.body中的内容保存HTML文件,而不是像

那样
url = "file:///your/path/to/downloaded/file.html"
dr.get(url)

答案 1 :(得分:0)

来自Scrapy doc

  

无论此参数的类型如何,存储的最终值都将是   是一个str(从来没有unicode或None)。

如果您正在使用Scrapy,我假设您在Python中使用Selenium。您可以使用lxml或其他库解析response.body字符串。 “让selenium使用response.body”到底是什么意思?