网站抓取-元素不可交互

时间:2020-06-25 08:36:26

标签: python-3.x web-scraping selenium-chromedriver

我正在尝试制作一个网络爬虫,它所做的基本上是自动加入抽奖活动。我的代码当前要做的是从页面中列出40个抽奖活动,然后从列表中选择随机href,然后访问页面。

现在我要使其自动单击输入抽奖按钮。当前代码:

URL = 'https://scrap.tf/raffles/ending'
pagee = requests.get(URL)
Soup = BeautifulSoup(requests.get(URL).content, 'html.parser')
#/
    for raffle_link in Soup.find_all(href=re.compile(r'/raffles/[A-Z\d]{6}')):
     Urls.append('{:<40}'.format('https://scrap.tf' + raffle_link['href']))
    

def plswork():
    numberofraffles = 0
    while numberofraffles <= 40:
        time.sleep(3)
        visit = random.choice(Urls)
        driver.get(visit)
        Urls.remove(visit)
        time.sleep(2)
        if (("raffle-start-time") == True):
            print("Raffle ended, retrying")
        else:
            time.sleep(2)
            Press = driver.find_element_by_id("raffle-enter")
            time.sleep(1)
            Press.click()
            numberofraffles += 1
            print("Raffles joined: {}".format(numberofraffles))
            time.sleep(3)

代码确实将我从列表中带到了一个随机href,但是之后,它没有按按钮,因此代码不断给我这个错误

  File "/home/igor/PycharmProjects/Untitled/Bot1.py", line 141, in <module>
plswork()

 File "/home/igor/PycharmProjects/Untitled/Bot1.py", line 134, in <module>
    Press.click()
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

我该如何解决?是什么原因造成的?

0 个答案:

没有答案