检查 selenium instagram post 是否为视频

Check if selenium instagram post is a video

我有一个机器人可以遍历所有用户 post 并获得喜欢的数量,它是 link。问题是遇到视频就断码了

def usermostlikedposts(self, username, nofposts):
        self.nav_user(username)
        for i in range(nofposts):
            try:
                post = self.browser.find_element_by_xpath('(//div[@class=\'eLAPa\']//parent::a)[{}]'.format(i+1))
                post.click()
                WebDriverWait(self.browser, 10).until(EC.presence_of_element_located((By.XPATH , '/html/body/div[4]/div[2]/div/article/div[3]/section[2]/div/div/button/span')))
                likes = self.browser.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[2]/div/div/button/span').get_attribute("innerHTML")
                link = post.get_attribute("href")
                self.likesposts[likes] = link
                x = self.browser.find_element_by_xpath('/html/body/div[4]/div[3]/button')
                x.click()
            except:
                pass

.

我不知道如何在视频上进行这项工作,我想让机器人在遇到视频时获得观看次数而不是喜欢的次数,但我未能实现这一点。我正在寻找一种方法来检查 post 是否是视频,并根据该条件编写代码

我设法解决了:

def usermostlikedposts(self, username, nofposts):
        self.nav_user(username)
        for i in range(nofposts):
            try:
                post = self.browser.find_element_by_xpath('(//div[@class=\'eLAPa\']//parent::a)[{}]'.format(i+1))
                post.click()
                WebDriverWait(self.browser, 10).until(EC.presence_of_element_located((By.XPATH , '/html/body/div[4]/div[2]/div/article/div[3]/section[1]/span[3]/button')))
                try:
                    likes = self.browser.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[2]/div/div/button/span').get_attribute("innerHTML")
                    link = post.get_attribute("href")
                    self.likesposts[likes] = link
                except:
                    pass
                x = self.browser.find_element_by_xpath('/html/body/div[4]/div[3]/button')
                x.click()
            except:
                pass