简体   繁体   English

无法使用 Selenium、Python 查看网站的整个页面源

[英]Not Able to See Entire Page Source of Website using Selenium,Python

I am trying to scrape this website https://script.google.com/a/macros/cprindia.org/s/AKfycbzgfCVNciFRpcpo8P7joP1wTeymj9haAQnNEkNJJ2fQ4FBXEco/exec我正在尝试抓取这个网站https://script.google.com/a/macros/cprindia.org/s/AKfycbzgfCVNciFRpcpo8P7joP1wTeymj9haAQnNEkNJJ2fQ4FBXEco/exec

I am using selenium and python.I am not able to view entire page source,Basically i have to scrape the table inside it and click on next button,but the code of next and table not visible on page source.Here is my code我正在使用 selenium 和 python。我无法查看整个页面源代码,基本上我必须刮取其中的表格并单击下一步按钮,但是页面源代码上看不到下一步和表格的代码。这是我的代码

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup


from selenium import webdriver

browser = webdriver.PhantomJS()
browser.get(link)


pass1 = browser.find_element_by_xpath("/html/body/div[2]/table[2]/tbody/tr[1]/td/div/div/div[2]/div[2]")
pass1.click()

time.sleep(30)

I am getting this error,NoSuchElementException.我收到此错误,NoSuchElementException。

There are two iframes present on the page, so you need to first switch on those iframe and then you need to click on the element.页面上有两个 iframe,因此您需要先打开这些 iframe,然后单击该元素。
And you can apply explicit wait on the element so that the script waits until the element is visible on the page.并且您可以对元素应用显式等待,以便脚本等待该元素在页面上可见。
You can do it like:你可以这样做:

browser = webdriver.PhantomJS()
browser.get(link)
browser.switch_to.frame(driver.find_element_by_id('sandboxFrame'))
browser.switch_to.frame(driver.find_element_by_id('userHtmlFrame'))
WebDriverWait(browser, 20).until(EC.presence_of_element_located((By.XPATH, "//div[contains(@class,'charts-custom-button-collapse-left')]//div"))).click()

Note: You have to add the following imports:注意:您必须添加以下导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM