-
-
Save alecxe/12b98722fd45c85ed1ddc1aa4c5e2a47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver import DesiredCapabilities | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36" | |
dcap = dict(DesiredCapabilities.PHANTOMJS) | |
dcap["phantomjs.page.settings.userAgent"] = user_agent | |
driver = webdriver.PhantomJS(desired_capabilities=dcap) | |
driver.get("http://express.co.uk/") | |
wait = WebDriverWait(driver, 10) | |
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".single-category"))) | |
# loop through all the frames | |
for index, frame in enumerate(driver.find_elements_by_css_selector("iframe")): | |
is_safe = frame.get_attribute("data-is-safeframe") == "true" | |
if is_safe: | |
print(frame.get_attribute("outerHTML")) | |
driver.switch_to.frame(index) | |
print(driver.page_source) | |
driver.switch_to.default_content() | |
print("----------") | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment