无法从python中搜索标记,但可以在chrome上查看
无法在此URL内搜索以下标记无法从python中搜索标记,但可以在chrome上查看,python,beautifulsoup,webdriver,Python,Beautifulsoup,Webdriver,无法在此URL内搜索以下标记 class="iw_component" id="c1417094965155" 我可以从桌面chrome浏览器查看,但在执行以下python脚本时无法读取 import time from selenium import webdriver from pyvirtualdisplay import Display display=Display(visible=0,size=(800,800)) display.start() driver=webdrive
class="iw_component" id="c1417094965155"
我可以从桌面chrome浏览器查看,但在执行以下python脚本时无法读取
import time
from selenium import webdriver
from pyvirtualdisplay import Display
display=Display(visible=0,size=(800,800))
display.start()
driver=webdriver.Firefox()
driver.get('url')
time.sleep(5)
title=driver.page_source
print title
driver.close()
display.stop()
可以使用类名来定位元素,方法是:
另外,可以使用sleep(5)来模拟/延迟python等待直到加载所有元素,而不是等待特定元素: 对于您来说,定位器策略的部分是:
presence_of_element_located((By.CLASS_NAME, "iw_component"))
您尝试加载的页面使用JavaScript动态生成其大部分内容(包括您想要查找的元素),因此您基本上需要模拟浏览器。代码可能重复,但仍然无法工作,谢谢!你应该把代码留在里面。否则这个问题就没有上下文了。对不起,这次事故!我引用它作为贡献,它似乎不起作用,但无论如何,谢谢!我正在使用python 2.7
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
driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
presence_of_element_located((By.CLASS_NAME, "iw_component"))