如何设置查询限制来过滤 Selenium 结果?
我设法获取了我想要的数据,但是现在我只需要它给我的前17个数据,我需要用这些数据来制作一种过滤器,因为我将使用它们的条件来使用它们的条件在另一个代码中使用。
from ctypes.wintypes import PINT
from logging import root
from tkinter import N
from hyperlink import URL
from numpy import number
from selenium import webdriver
import selenium
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import time
url = "https://blaze.com/pt/games/double"
#absolute path
firefox_driver_path = "/Users/Antônio/Desktop/roletarobo/geckodriver.exe"
firefox_options = Options()
firefox_options.add_argument("--headless")
webdriver = webdriver.Firefox(
executable_path = firefox_driver_path,
options = firefox_options
)
with webdriver as driver:
# timeout
wait = WebDriverWait(driver, 1)
# retrieve data
driver.get(url)
#wait
wait.until(presence_of_element_located((By.ID, "roulette-recent")))
results = driver.find_elements(by=By.CLASS_NAME, value='entry')#find_elements_by_css_selector('#roulette .sm-box .number')
for quote in results:
quoteArr = quote.text.split('\n')
print(quoteArr)
driver.close()
我的结果在下面,
['']
['13']
['4']
['11']
['11']
['13']
['6']
['5']
['9']
['14']
['5']
['']
['12']
['10']
['5']
['']
['3']
['13']
['']
['']
['Douglas', 'R$ 39.48']
['MSK', 'R$ 25.27']
['Marcz10', 'R$ 23.69']
['Jeferson ☘️', 'R$ 19.74']
['Pai_daBlaze', 'R$ 12.35']
['Lucianotelles1993', 'R$ 11.84']
['Alexandra souza', 'R$ 11.84']
['Taynara Luna', 'R$ 9.87']
['Mylla coutinho', 'R$ 9.87']
['Marcos smith', 'R$ 9.87']
因为您可以看到他给了我几个回报,但我只需要从上到下才需要前17个,我不需要以下这些名称,也不需要这些信息。我该怎么做?
I managed to get the data I wanted with selenium, but now I only need the first 17 data that it gives me, I need to make a kind of filter with this data, because I'm going to use conditions on top of them to use in another code.
from ctypes.wintypes import PINT
from logging import root
from tkinter import N
from hyperlink import URL
from numpy import number
from selenium import webdriver
import selenium
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import time
url = "https://blaze.com/pt/games/double"
#absolute path
firefox_driver_path = "/Users/Antônio/Desktop/roletarobo/geckodriver.exe"
firefox_options = Options()
firefox_options.add_argument("--headless")
webdriver = webdriver.Firefox(
executable_path = firefox_driver_path,
options = firefox_options
)
with webdriver as driver:
# timeout
wait = WebDriverWait(driver, 1)
# retrieve data
driver.get(url)
#wait
wait.until(presence_of_element_located((By.ID, "roulette-recent")))
results = driver.find_elements(by=By.CLASS_NAME, value='entry')#find_elements_by_css_selector('#roulette .sm-box .number')
for quote in results:
quoteArr = quote.text.split('\n')
print(quoteArr)
driver.close()
My result is below
['']
['13']
['4']
['11']
['11']
['13']
['6']
['5']
['9']
['14']
['5']
['']
['12']
['10']
['5']
['']
['3']
['13']
['']
['']
['Douglas', 'R$ 39.48']
['MSK', 'R$ 25.27']
['Marcz10', 'R$ 23.69']
['Jeferson ☘️', 'R$ 19.74']
['Pai_daBlaze', 'R$ 12.35']
['Lucianotelles1993', 'R$ 11.84']
['Alexandra souza', 'R$ 11.84']
['Taynara Luna', 'R$ 9.87']
['Mylla coutinho', 'R$ 9.87']
['Marcos smith', 'R$ 9.87']
As you can see he gave me several returns but I only need the first 17 from top to bottom in order, I don't need these names below nor this information that is in front of them. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要提取前17个数据,您可以使用 >您可以使用以下任何一个定位器策略:
使用 css_selector ::
/p>
使用 xpath :
控制台输出:
To extract the first 17 datas you can use List Slicing and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
Using XPATH:
Console Output:
我认为
driver.find_elements
返回结果作为数组,因此您可以使用数组进行结果。I think
driver.find_elements
returns result as a array, so you can use array for result.