Selenium PhantomJS永远不会完成装载/不完整装载

时间:2017-06-28 09:39:13

标签: python selenium phantomjs

我试图从https://www.fmovies.is获取嵌入的视频网址。我使用selenium.PhantomJS()。如果我使用selenium.Firefox()驱动程序,完全相同的代码完美地工作。似乎我在等待阶段做错了什么。

如果有人能指出我做错了什么,我真的很感激。

from bs4 import BeautifulSoup
from selenium import webdriver
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import DesiredCapabilities

desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
desired_capabilities['phantomjs.page.customHeaders.User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5)AppleWebKit 537.36 (KHTML, like Gecko) Chrome"
desired_capabilities['phantomjs.page.customHeaders.Accept'] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"

url = "https://fmovies.is/film/kung-fu-panda-2.9kx/q8kkyj"

driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'],desired_capabilities=desired_capabilities)
driver.get(url)

try:
    element = WebDriverWait(driver, 100).until(EC.presence_of_element_located((By.ID, "jw")))

finally:
    driver.find_element_by_id("player").click()
    pageSource = driver.page_source
    soup = BeautifulSoup(pageSource,'lxml')
    url = soup.find("video",{"class":"jw-video"})
    print url
    videoURL = ''
    if url: 
        videoURL = url['src']
    print videoURL

0 个答案:

没有答案