对于如何在python中使用SeleniumWeb驱动程序获取文本感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍pythonselenium获取文本,并为您提供关于asp.net–在.net中
对于如何在python中使用Selenium Web驱动程序获取文本感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍python selenium 获取文本,并为您提供关于asp.net – 在.net中使用selenium 2.0 web驱动程序的示例/教程?、Python Selenium Web驱动程序:send_keys在无头模式下不起作用、Selenium Web驱动程序,用于使用Python进行电报数据提取、Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程的有用信息。
本文目录一览:- 如何在python中使用Selenium Web驱动程序获取文本(python selenium 获取文本)
- asp.net – 在.net中使用selenium 2.0 web驱动程序的示例/教程?
- Python Selenium Web驱动程序:send_keys在无头模式下不起作用
- Selenium Web驱动程序,用于使用Python进行电报数据提取
- Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程
如何在python中使用Selenium Web驱动程序获取文本(python selenium 获取文本)
我正在尝试使用Selenium
Web驱动程序获取文本,这是我的代码。请注意,我不想使用Xpath,因为在我的情况下,每次重新启动网页时id都会更改,请提供帮助。
我的代码:
text=driver.find_element_by_class_name("current-stage").getText("my text")
HTML:
<spanid="yui_3_7_0_4_1389185744113_384">my text</span>
答案1
小编典典你只想.text
。
然后,您可以在得到验证 后对其 进行验证,不要尝试传递您 期望的 内容。
asp.net – 在.net中使用selenium 2.0 web驱动程序的示例/教程?
我试过搜索,但只能找到java,没有关于.net和selenium 2.0 web驱动程序
解决方法
http://seleniumhq.org/docs/03_webdriver.html
using OpenQA.Selenium.Firefox; using OpenQA.Selenium; class GoogleSuggest { static void Main(string[] args) { IWebDriver driver = new FirefoxDriver(); //Notice navigation is slightly different than the Java version //This is because 'get' is a keyword in C# driver.Navigate().GoToUrl("http://www.google.com/"); IWebElement query = driver.FindElement(By.Name("q")); query.SendKeys("Cheese"); System.Console.WriteLine("Page title is: " + driver.Title); driver.Quit(); } }
Python Selenium Web驱动程序:send_keys在无头模式下不起作用
在选项中尝试添加此参数
chrome_options.add_argument("user-agent = my-user-agent")
my-user-agent
对于每个系统都是不同的,请检查您的代理商Google my user agent
并将其插入选项中。
与此同时,我觉得在您的代码中,while
是不必要的,您可以删除它。
由于您尝试访问的文本框需要花费一些时间才能加载,因此请在提取文本框时尝试在此处使用显式等待
WebDriverWait(driver,20).until(EC.presence_of_element_located((By.CSS_SELECTOR,"#identifierId")))
当您必须输入文本并按Enter时,请使用以下代码段更新代码:
username = WebDriverWait(driver,"#identifierId")))
username.send_keys("Emailuser",Keys.ENTER)
Selenium Web驱动程序,用于使用Python进行电报数据提取
基本上,您需要通过从硒中获取html来初始化bs4(BeautifulSoup)变量。
from bs4 import BeautifulSoup
content = driver.page_source
soup = BeautifulSoup(content,"html.parser")
然后,您可以使用soup
变量,如下所示:
if soup.find('li',class_="pagination-paginationMeta") is not None:
pageCount = int(filterPageNumber(
soup.find('li',class_="pagination-paginationMeta").text))
else:
pageCount = 1
您好我已经使用Selenium,requests,bs4 for Myntra实现了全功能的刮板,您可以在此处Github-Repo进行签出 (P.S.我没有做适当的文档,并且代码实际上是RAW,所以很难理解。)
Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程
如何解决Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程?
您可以通过chrome://downloads/
使用驱动程序进行导航来获取每次下载的状态。
要等待所有下载完成并列出所有路径,请执行以下操作:
def every_downloads_chrome(driver):
if not driver.current_url.startswith("chrome://downloads"):
driver.get("chrome://downloads/")
return driver.execute_script("""
var items = downloads.Manager.get().items_;
if (items.every(e => e.state === "COMPLETE"))
return items.map(e => e.fileUrl || e.file_url);
""")
# waits for all the files to be completed and returns the paths
paths = webdriverwait(driver, 120, 1).until(every_downloads_chrome)
print(paths)
解决方法
我正在通过chromewebdriver(windows)使用selenium和python来自动执行从不同页面下载大量文件的任务。我的代码可以运行,但是解决方案远非理想:下面的函数单击网站按钮,该按钮会启动Java脚本函数,该函数会生成PDF文件,然后下载该文件。
我必须使用静态等待才能等待下载完成(丑陋)。我无法检查文件系统以确认下载何时完成,因为我使用的是多线程(从不同页面下载很多文件)一次),并且文件名也会在网站本身中动态生成。
我的代码:
def file_download(num,drivervar):
Counter += 1
try:
drivervar.get(url[num])
download_button = WebDriverWait(drivervar,20).until(EC.element_to_be_clickable((By.ID,''download button ID'')))
download_button.click()
time.sleep(10)
except TimeoutException: # Retry once
print(''Timeout in thread number: '' + str(num) + '',retrying...'')
.....
是否可以在webdriver中确定下载完成?我想避免使用time.sleep(x)。
非常感谢。
关于如何在python中使用Selenium Web驱动程序获取文本和python selenium 获取文本的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于asp.net – 在.net中使用selenium 2.0 web驱动程序的示例/教程?、Python Selenium Web驱动程序:send_keys在无头模式下不起作用、Selenium Web驱动程序,用于使用Python进行电报数据提取、Selenium(Python)-等待使用Chrome Web驱动程序完成下载过程的相关知识,请在本站寻找。
本文标签: