A
A
Apache2020-11-04 13:14:42
Python
Apache, 2020-11-04 13:14:42

How to click a button on a site, parsing?

I have a parser (don't scold me for it), it does the job fine, but there was a problem that could not be solved. I can't click on the site button. I'm using selenium to click on a button, but it's not convenient for my task. Advise how else you can click the buttons of sites and it is desirable that the browser does not open. Or help with the error, it will be below the code.

Code
import requests
from bs4 import BeautifulSoup as BS
import re
import webbrowser
from selenium import webdriver 

def BUY_SK(url):
    r = requests.get(url)
    html = BS(r.content, 'html.parser')
    #hidden_tags = str(html.find("input", {"type": "hidden"}))[50:][:-3]
    #webbrowser.open(url, new=2)
    driver = webdriver.Firefox()
    driver.get(url)
    element = driver.find_element_by_css_selector('.snap._color.buy-user-good')
    element.click() # Ошибка из-за этого элемента



def SKINKEEN():
    regular = re.compile(r'<a\s+(?:[^>]*?\s+)?href=([""])(.*?)\1')

    r = requests.get('https://skinkeen.ru/')
    html = BS(r.content, 'html.parser')

    for el in html.select('.item_view'):
        title = el.select('.item_view__info > span')
        title = title[0].text[8:][:-4]
        if int(title) >= 45:
            gun__ = all_links = el.find_all('a', href=True)
            gun = regular.split(str(gun__[0]))
            gun__info_ = html.select('.item_view > a')

            print('\n[INFO] Найдено подходящие оружие! Скидка', str(title) + '%\n', gun__info_[0].text)
            print('https://skinkeen.ru/' + str(gun[2]), '\n')

            BUY_SK('https://skinkeen.ru/' + str(gun[2]))

        else:
            print('[INFO] Оружие не подходит: Скидка', str(title) + '%')

SKINKEEN()


Mistake
Traceback (most recent call last):
File "C:/py/CSGO Trade Bot v 0.1/CSGOTB.py", line 41, in
SKINKEEN()
File "C:/py/CSGO Trade Bot v 0.1/CSGOTB.py", line 36, in SKINKEEN
BUY_SK('https://skinkeen.ru/' + str(gun[2]))
File "C:/py/CSGO Trade Bot v 0.1/CSGOTB.py", line 15, in BUY_SK
element.click()
File "C:\py\CSGO Trade Bot v 0.1\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\py\CSGO Trade Bot v 0.1\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\py\CSGO Trade Bot v 0.1\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\py\CSGO Trade Bot v 0.1\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: Element is not clickable at point (539,646) because another element obscures it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
acwartz, 2020-11-04
@igor_89squad

View the DOM device by the browser, understand what to change on the page so that the desired element is not obscured, perform the same actions with the script, profit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question