要获取网站的最终html代码(在此示例中为http://www.rtve.es/drmn/embed/video/3886778/),我需要模拟两次鼠标点击。
按照之前的问题和答案,我在Python 2.7.13中构建了以下代码:
from selenium import webdriver
import time
import requests
import os
from bs4 import BeautifulSoup
driver = webdriver.PhantomJS(service_log_path=os.path.devnull)
driver.get('http://www.rtve.es/drmn/embed/video/3886778/')
time.sleep(3)
print driver.title # ---> correct title is shown
driver.save_screenshot('out.png') # ---> correct screenshot is saved to disc
driver.find_element_by_xpath("//*[@id='embed']/div/a/span/img").click() # ---> doesn't seem to work
el=driver.find_element_by_xpath("//*[@id='embed']/div/a/span/img")
el.location
el.size # ---> correct position and size of 'play'-icon is shown
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 5, 5)
action.click()
action.perform() # ---> nothing happens
driver.save_screenshot('out2.png') # ---> still the picture of the freeze frame
嗯,这似乎不起作用......我只需要模仿以下内容: - 在任意位置单击鼠标 - 等到现场广告出现 - 等待3秒钟直到"盐水促销/跳过广告"出现 - 另一只鼠标点击"盐浆促销"元件 - 阅读最后的HTML
任何提示?