使用 selenium 和 PhantomJS 获取 Google 学术搜索的结果

Getting results of Google Scholar search with selenium and PhantomJS

下面的代码应该打印 this 页的内容。

from selenium import webdriver
driver = webdriver.PhantomJS()
link = u'https://scholar.google.co.il/scholar?q=The+Trellis+Security+Infrastructure:+{A}+Layered+Approach+to+Overlay+Metacomputers'
driver.get(link)
print driver.page_source

然而,它打印的是:

<html><head></head><body></body></html>

如果我使用 webdriver.Firefox() 而不是 webdriver.PhantomJS(),它会起作用。我知道 PhantomJS 已正确安装,因为上面的代码过去工作得很好。这意味着什么?

您使用的 Selenium/PhantomJs 是哪个版本? 我试过:

  • 硒 3.6.0
  • PhantomJs 2.1.1

这个:

from selenium import webdriver

driver = webdriver.PhantomJS(executable_path=r'PathTo/phantomjs-2.1.1-macosx/bin/phantomjs')
link = 'https://scholar.google.co.il/scholar?q=The+Trellis+Security+Infrastructure:+{A}+Layered+Approach+to+Overlay+Metacomputers'
driver.get(link)
print (driver.page_source)

而且有效。