如何修复循环并单击每个元素

时间:2019-05-06 11:55:34

标签: python selenium

我正在使用Windows 10和python 3,我需要先单击第一个元素并返回,然后再次单击第二个并再次返回,然后单击到3、4、5个元素,直到完成。

我正在使用此代码,它仅返回第一个元素。

import csv
from parsel import Selector
from time import sleep
from selenium import webdriver


driver = webdriver.Chrome()

driver.get('https://startup-days-2019.events.startupinvest.ch/participants')

sel = Selector(text=driver.page_source)

lists = sel.xpath('//*[@class="ReactVirtualized__Grid__innerScrollContainer"]/div//@style').extract()


while True:
    driver.get('https://startup-days-2019.events.startupinvest.ch/participants')
    sleep(5)

    sel = Selector(text=driver.page_source)

    lists = sel.xpath('//*[@class="ReactVirtualized__Grid__innerScrollContainer"]/div//@style').extract()
    try:
        for lss in lists:
            ss='//*[@style="%s"]'%lss
            # ss='//*[@style="height: 130px; left: 0px; position: absolute; top: 130px; width: 100%;"]'

            driver.find_element_by_xpath(ss).click()
            sleep(5)
    except:
        pass

请检查代码。 我们希望结果将是单击每个元素并获得列出的所有数据的详细信息

谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用并以json格式获取所有信息。将// Does not work timer(1000) .pipe(take(10)) // 10 second delay .subscribe(() => window.print()); // Works timer(1000) .pipe(take(10)) // 10 second delay .toPromise() .then(() => window.print()); 的值从25更改为338,并在一个请求中吸引所有参与者。

pageSize

要获得此权限,您应该先滚动并收集所有import requests response = requests.get('https://startup-days-2019.events.startupinvest.ch/api/v2/events/3778/participants:search?pageSize=25&view=1&filter.query=&order_by=') # to get response in text format, use response.text participants = response.json()["participants"] for participant in participants: first_name = participant["user"]["first_name"] last_name = participant["user"]["last_name"] organisation_name = participant["organisation_name"] print(s"name: {first_name} {last_name}, organisation: {organisation_name}")

href