简体   繁体   English

使用 selenium 发出请求时是否可以获取源代码?

[英]Is it possible to get source code when making a request with selenium?

There's an element on the website that I am trying to mess around with, but getting to that element is hard, because the ID of it changes every time you visit the page.网站上有一个元素,我想弄乱它,但要访问该元素很困难,因为每次访问该页面时它的 ID 都会更改。

So, I somehow want to get source code whenever selenium enters the website and use regex to get the correct ID of that element.所以,我想在 selenium 进入网站时获取源代码并使用正则表达式来获取该元素的正确 ID。

Any ideas on how to do this?关于如何做到这一点的任何想法? Or any ideas how to get the wanted element in another way?或者任何想法如何以另一种方式获得想要的元素?

<select role="listbox" aria-required="true" aria-labelledby="label-agreement" class="x-form-text x-form-field " name="agreement" tabindex="0" id="tts-6535350604697758">
  <option value=""></option>
  <option value="1">I agree</option>
  <option value="2">I don't agree</option>
</select>

You can use the name attribute, it seem unique enough你可以使用name属性,它看起来足够独特

driver.find_element_by_name('agreement')

Or by aria-labelledby attribute或者通过aria-labelledby属性

driver.find_element_by_css_selector('[aria-labelledby="label-agreement"]')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发出获取请求时的403响应 - 403 response when making a get request 是否可以在 python 中使用 selenium 获得元素的 xpath(源)? - Is it possible to get the xpath (source) of an element using selenium in python? 无法获取Zomato网站的HTML源代码Selenium、Python - Unable to get HTML source code Selenium , Python of Zomato website 如何使用 python 在 selenium 中获取新页面的源代码 - how to get new page's source code in selenium with python Selenium:获取未在“检查元素”中显示的 innerHTML 代码源 - Selenium: Get code source of innerHTML that doesn't show in 'inspect element' 如何使用 Python 和 Selenium 获取未解析的 HTML 源代码 - How to get unparsed HTML source code with Python and Selenium 硒:如何在单击按钮后获取页面源代码 - selenium: How to get page source code after clicking a button 如何在 Odoo 中获得好的源代码以便能够与 selenium 一起使用? - How to get good source code in Odoo to be able to use with selenium? 从网站获取完整的源代码 python selenium - Get full source code from a website python selenium 当源代码没有改变,但是 selenium webdriver deos 没有返回元素 - When source code does not changed, but selenium webdriver deos not return the element
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM