如何通过python用Selenium取得网页元素数据

卧枝惠中天 2020-04-21 01:06:20
网页部分代码如下
想提取到 id="orderId0" 对应的'beb-10008880'这个数据,并打印出来
或者通过'beb-10008880'来找到他对应的id="orderId0"。
请大神指点!

<a class="strongorderid" id="orderId0" name="orderId0" href="javascript:void(0);"
onclick="openOrderDetailWindow('/pro.accf/order/manage/detail/beb-10008880','beb-10008880')">beb-10008880</a>
...全文
416 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
卧枝惠中天 2020-04-23
  • 打赏
  • 举报
回复
引用 2 楼 nieoding 的回复:

# 方法1:
elem.get_attribute("innerHTML").splitlines()[0])
# 方法2:
driver.execute_script('return arguments[0].firstChild.textContent;', elem).strip()

谢谢!
卧枝惠中天 2020-04-23
  • 打赏
  • 举报
回复
引用 1 楼 的回复:
试试这个 .get_attribute()
谢谢!
nieoding 2020-04-21
  • 打赏
  • 举报
回复

# 方法1:
elem.get_attribute("innerHTML").splitlines()[0])
# 方法2:
driver.execute_script('return arguments[0].firstChild.textContent;', elem).strip()

圣 经 宾 2020-04-21
  • 打赏
  • 举报
回复
试试这个
.get_attribute()
amazon 好评书籍 Get to grips with automated web testing with the amazing power of Selenium WebDriver About This Book Utilize Selenium WebDriver features for automation testing using outstanding techniques and strategies Learn how to build, customize, and maintain Selenium frameworks Packed with numerous practical examples, this book covers all the functions and commands that will help you grasp Selenium functions quickly Who This Book Is For If you are a developer who wants to migrate from Selenium RC or any other automation tool to Selenium WebDriver, then this book is for you. Knowledge of automation tools is necessary to follow the examples in this book. What You Will Learn Handle the Selenium IDE and Builder features efficiently Integrate JavaScript with the Selenium IDE Practice cross-browser testing in your favorite browser Run automated Selenium WebDriver tests on different cloud servers Go through all the Selenium WebDriver functions Discover how to handle the features not supported by Selenium WebDriver Observe various testing techniques using available frameworks Develop your own Selenium framework for well-organized web application testing In Detail This book will help you seamlessly migrate from Selenium RC to Selenium WebDriver. You will be able to quickly develop automated tests with little effort. Based on popularity, support, and usage, the scripts throughout the book are in Java. We will start off by familiarizing you with the Selenium IDE, teaching you its functions, and using it to automate and debug a complex website. Next, we will harness the power of Selenium WebDriver to perform cross-browser automation tests. We will then go to the next level and run automation tests on the cloud. After this, we will cover a wide range of functions provided by the Selenium WebDriver API that can be used for effective web automation tests. Finally, you will learn how to perform Data-Driven and Behavior-Driven tests.

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧