Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium:获取下一步按钮单击内容_Python_Html_Selenium_Web Scraping_Quora - Fatal编程技术网

Python Selenium:获取下一步按钮单击内容

Python Selenium:获取下一步按钮单击内容,python,html,selenium,web-scraping,quora,Python,Html,Selenium,Web Scraping,Quora,在Quora网站上,我试图通过点击“查看投票人”来获得每个答案的投票人姓名,但我没有得到正确的结果。 例如,在Quora问题链接上,您有两个答案,第一个有5个投票人,第二个有2个。我从下面的代码中得到的结果是5,5 all_upvotes= browser.find_elements_by_class_name('ExpandedVoterListItem') for p in all_upvotes: p.click() time.sleep(10) wait.unt

在Quora网站上,我试图通过点击“查看投票人”来获得每个答案的投票人姓名,但我没有得到正确的结果。 例如,在Quora问题链接上,您有两个答案,第一个有5个投票人,第二个有2个。我从下面的代码中得到的结果是5,5

all_upvotes= browser.find_elements_by_class_name('ExpandedVoterListItem')
for p in all_upvotes:
    p.click()
    time.sleep(10)

    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.modal_content.modal_body'))) 

    upvoter_name = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'span.feed_item_answer_user'))) 

    time.sleep(10)
    print ('number of upvoters found for this answer %d' % len(upvoter_name)) 
    # print upvoters names
    for line in upvoter_name:
           print(line.text)

看起来您并不是每次都选择“查看投票人”链接,至少在您提供的脚本中是这样。相反,请使用以下操作顺序:

all_upvotes= browser.find_elements_by_link_text('View Upvoters') # Finds all "View Upvoters" buttons (they are links actually)
for p in all_upvotes:

    p.click() # Opens list of upvoters

    # No need to sleep or wait for anything else, just wait for items you want, namely the name of upvoter (which is again a link):
    upvoter_name = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, 'a.user')))

    print ('number of upvoters found for this answer %d' % len(upvoter_name)) 

    # print upvoters names
    for line in upvoter_name:
        print(line.text)

    # Now we need to close list of upvoters, to open the next one on next iteration of the loop:
    close_button = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'span.modal_close'))) 
    close_button.click()