简体   繁体   English

有什么方法可以使用 python selenium 访问此文本?

[英]Is there any way to access this text using python selenium?

I want to use selenium to evaluate the accuracy of chess moves within my dataset of games for an AI.我想使用 selenium 来评估我的 AI 游戏数据集中国际象棋移动的准确性。 So far, I can access the evaluation bar, but not the FEN (it returns an empty string).到目前为止,我可以访问评估栏,但不能访问 FEN(它返回一个空字符串)。 Is there any way to access the FEN within this site .有什么方法可以访问这个站点内的 FEN。

This is the textbox:这是文本框: 在此处输入图像描述

I want to grab this: rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2我想抓住这个: rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2

This is the HTML of the textbox:这是文本框的 HTML:

<input type="text" readonly="" class="text" id="fen_position" name="fen_position" value="" style="width:350px;font-size: 0.7em !important;padding: 3px 6px !important;">

Here is the relevant portion of my code:这是我的代码的相关部分:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

options = Options()
options.headless = True

browser = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
browser.get("https://www.365chess.com/analysis_board.php")

browser.implicitly_wait(5); fen = browser.find_element_by_id('fen_position').text
print(fen)

So the FEN is an <input> for inputs the value is stored as a "value" in properties you can use the.get_property("value") to access it.因此,FEN 是输入的<input>值,该值存储为属性中的“值”,您可以使用 .get_property("value") 来访问它。 Here is the working code.这是工作代码。

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys

options = Options()
options.headless = True

browser = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
browser.get("https://www.365chess.com/analysis_board.php")

browser.implicitly_wait(5); fen = browser.find_element_by_id('fen_position').get_property("value")
print(fen)

Happy coding:)快乐编码:)

暂无
暂无

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

相关问题 有没有办法使用 selenium 点击“纯文本”? - Is there any way to click on "plain text" using selenium? 如何使用 Selenium /Python 访问 HTML 文本? - How to access HTML text using Selenium /Python? 有没有办法在 python selenium 中使用 send_keys 更改文本的颜色? - Is there any way to change the color of a text using send_keys in python selenium? 有没有办法使用 python selenium 获取网站的所有“内部 html 文本”及其对应坐标? - Is there any way to get all the “inner html text” of a website and its corresponding coordinates using python selenium? Python Selenium - 有什么方法可以在这个文本框中发送文本? - Python Selenium - Any way to get send text within this textbox? 使用 selenium python 以任何方式“让人们加入 Meet” - Any way to “Admit people in Meet” using selenium python 如何在 Python 中使用 Selenium 访问 div 标签内的文本? - How to access text inside div tags using Selenium in Python? 使用 Selenium-Python 检查页面中是否存在文本的最佳方法 - Best way to check if text exist or not in the page using Selenium- Python 在 Python 中使用 Selenium 搜索不区分大小写的文本的最佳方法是什么? - What is the best way to search case insensitive text using Selenium in Python? 有没有办法使用 Selenium 在 Python 中找到动态变化的元素的“内部文本”? - Is there a way to find the 'inner text' of elements that change dynamically in Python using Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM