【问题标题】:Automating a webpage自动化网页
【发布时间】:2018-09-11 13:34:15
【问题描述】:

我想在循环中对现有网页执行某些操作

  1. 点击侧边菜单栏。
  2. 点击过滤选项。
  3. 选择某个链接打开链接。
  4. 转到下一页。
  5. 更改已打开链接下拉菜单中的选项。
  6. 单击某个按钮。 如何使用编码执行此操作?如果我已经在使用 selenium,哪种语言更可取?

【问题讨论】:

  • 您好 Shreya Shubhangi,欢迎来到 Stack Overlow。现在很难理解你的答案是什么,你只能猜测。请编辑您的问题以澄清您的问题,并添加导致该问题的代码的最小示例。
  • 欢迎来到 SO!请阅读this help topic,以便您重新表述您的问题。
  • 为什么要使用另一种“语言”? Selenium 有问题吗?

标签: javascript selenium automation coding-style


【解决方案1】:

Selenium 将为您完成所有这些工作,甚至更多!以下是使用 Firefox 的示例;您可以轻松使用 Chrome、IE 等。

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.accept_untrusted_certs = True
wd = webdriver.Firefox(executable_path="C:/Utility/geckodriver.exe", firefox_profile=profile)


url = "https://www.google.com/"
wd.get(url)


# download geckodriver for windows 64-bit from here
# https://github.com/mozilla/geckodriver/releases

你需要专注于这样的事情:

 find_element_by_class_name(name)

    Finds an element by class name.
    Args:   
        name: The class name of the element to find.

    Returns:    
        WebElement - the element if it was found

    Raises: 
        NoSuchElementException - if the element wasn’t found

    Usage:  
    element = driver.find_element_by_class_name('foo')

查看下面的链接了解更多信息。

https://selenium-python.readthedocs.io/api.html

https://www.seleniumhq.org/docs/

【讨论】:

    猜你喜欢
    • 2020-10-25
    • 1970-01-01
    • 2017-04-05
    • 2013-03-25
    • 2014-03-01
    • 2017-08-09
    • 2019-01-18
    相关资源
    最近更新 更多