我正在尝试使用selenium web驱动程序获取文本,这是我的代码.请注意,我不想使用Xpath,因为在我的情况下,ID会在每次重新启动网页时发生变化,请帮忙.
我的代码:
text=driver.find_element_by_class_name("current-stage").getText("my text")
Run Code Online (Sandbox Code Playgroud)
HTML:
<span class="current-text" id="yui_3_7_0_4_1389185744113_384">my text</span>
Run Code Online (Sandbox Code Playgroud) 线:
<div class="btn btn-second-in-pair-not-desired btn-tall">Clear search</div>
<div class="btn btn-second-in-pair-not-desired btn-tall">Raw Search</div>
<div class="btn btn-second-in-pair-not-desired btn-tall">Basic Search</div>
<div class="btn btn-primary-stand-alone btn-tall search-btn">Search</div>
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所尝试过的 - “.btn:contains('Clear search')” 但 selenium 无法捕获它
我打开启用了 Browsec 扩展的 Chrome 浏览器的所有努力都失败了。这是我上次尝试过的 -
# Configure the necessary command-line option.
options = webdriver.ChromeOptions()
options.add_argument(r'--load-
extension=C:\Users\lap0042\AppData\Local\Google\Chrome\User
Data\Default\Extensions\omghfjlpggmjjaagoclmmobgdodcjboh')
# Initalize the driver with the appropriate options.
driver = webdriver.Chrome(chrome_options=options)
driver.get("http://stackoverflow.com")
Run Code Online (Sandbox Code Playgroud)
这会导致错误“无法从 .Manifest 文件加载扩展名丢失或无法读取”
搜索此错误后,我发现 Manifest.json 文件应重命名为 manifest.json.txt,但这样做会导致相同的错误。
任何帮助将不胜感激
python selenium google-chrome google-chrome-extension selenium-chromedriver