我有以下代码:
from selenium import webdriver
# Set url and path
url = 'https://osu.ppy.sh/beatmapsets?m=0'
driver = webdriver.Chrome(executable_path=r"C:\Users\Gabri\anaconda3\chromedriver.exe")
driver.get(url)
# Select the item that i want
try:
dif = driver.find_element_by_css_selector('div.beatmapset-panel__beatmap-dot')
dif.text
print(dif)
except:
print('not found')
我正在尝试选择此地图难度“紫色专家”->https://imgur.com/a/G224rka但是我无法继续我的代码,因为输出是"<selenium.webdriver.remote.webelement.WebElement (session="3cdaf38d0673d0aebe49733d629eae5c", element="60d6241b-80f7-42c8-bf38-9fd2c8574b08")>"
,我希望它是一个类似“expert”或--bg:var(--diff expert);“我如何翻译或转换?”?我确实尝试过用'[class*="beatmapset-panel__beatmap-dot"'
进行选择,结果是一样的。有人能帮我吗
要打印元素文本,需要按以下方式更改代码:
您需要将鼠标悬停在某个元素上,然后等待数据出现并获取其文本:
下面是列表中第一个游戏的片段。要获得所有游戏,您需要另一个循环
我使用
ActionChains
将鼠标悬停在元素上。即使对我来说,找到这个网站的定位器也不容易输出:
要通过级别列表进行迭代,请使用此css选择器:
并迭代此定位器:
.beatmapsets\uuuu项目行:第n个类型(1)。beatmapsets\uuuu项目:第n个类型(1)。beatmapset-panel\uuu信息行额外
.beatmapsets\uuuu项目行:第n个类型(2)。beatmapsets\uuuu项目:第n个类型(1)。beatmapset-panel\uuu信息行额外
更新: 要获得分数,请使用:
输出将是:
另外,检查这个关于如何将结果放入一个列表的答案:Trouble retrieving elements and looping pages using next page button
最后在这里阅读有关css选择器的内容:https://www.w3schools.com/cssref/css_selectors.asp
我通常更喜欢用它们,因为它们比较短
相关问题 更多 >
编程相关推荐