當我想要獲取URL頁面的源時,我在Windows7上遇到Selenium和PhantomJS的問題。 browser.page_source
只返回<html><head></head></html>
。我已經睡了browser.page_source
之前,但它沒有幫助。Python:Selenium with PhantomJS空白頁面源
這是我的代碼:
from selenium import webdriver
browser = webdriver.PhantomJS('phantomjs-1.9.7-windows\phantomjs.exe')
url = 'myurl'
browser.get(url)
print browser.page_source
在Linux上使用相同版本的PhantomJS它完美的作品。它也適用於Windows Server 2003.
嘗試一些調試,捕捉例如 –
截圖的截圖是空的,空白圖像。 我以爲這是PhantomJS的問題,我試圖用PyQt4的webkit加載頁面,但結果是一樣的,只是和
標籤。 這是給我這個頭痛的URL:https://www.homesearch.com/browse?fulltextquery=miami+fl&page=0 –導航到某些_https_:// url時,我遇到了同樣的問題。使用'time.sleep(few_seconds)'或webdriver的[預期條件](http://selenium-python.readthedocs.org/en/latest/api.html#selenium.webdriver.support.expected_conditions.presence_of_element_located)等待一些元素在調用browser.get(url)後出現在頁面上' –