[英]Is there any way to access this text using python selenium?
我想使用 selenium 来评估我的 AI 游戏数据集中国际象棋移动的准确性。 到目前为止,我可以访问评估栏,但不能访问 FEN(它返回一个空字符串)。 有什么方法可以访问这个站点内的 FEN。
我想抓住这个: rnbqkbnr/ppp1pppp/8/3p4/4P3/8/PPPP1PPP/RNBQKBNR w KQkq d6 0 2
这是文本框的 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;">
这是我的代码的相关部分:
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)
因此,FEN 是输入的<input>
值,该值存储为属性中的“值”,您可以使用 .get_property("value") 来访问它。 这是工作代码。
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)
快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.