【问题标题】:RoboBrowser getting type error 'NoneType' object is not subscriptableRoboBrowser 获取类型错误“NoneType”对象不可下标
【发布时间】:2017-06-04 01:45:27
【问题描述】:

我正在尝试制作一个 kahoot 垃圾邮件发送者,它输入由用户决定的密码和用户名。运行此代码时出现类型错误:

import re
from robobrowser import RoboBrowser

#Getting pin number for kahoot
pin = int(input("What is the pin number of the Kahoot?"))
# Getting number of bots to be deployed
number_of_bots = int(input("How many bots would you like?"))
#Getting base name
name = str(input("What would you like your bots' name to be (number will be added to the end of the name)?"))
#counter
counter = 0
#Number on end of name
num = 1

def joinKahoot(pin, number_of_bots, name):
    browser = RoboBrowser(history = True)
    #Connect to kahoot's website
    browser.open("https://kahoot.it/")
    pin_form = browser.get_form()
    pin_form['inputSession'].value == pin
    browser.submit_form(pin_form)

    name_form = browser.get_form()
    name_form["username"].value == name
    browser.submit_form(name_form)

#While counter is less than number_of_bots flood kahoot
while counter < number_of_bots:
    joinKahoot(pin, number_of_bots, name)
    counter += 1
    num += 1
    name = name + str(num)

错误:

Traceback (most recent call last):
  File "C:\Users\Vincent\Documents\Kahoot Spammer V2\flood.py", line 29, in <module>
    joinKahoot(pin, number_of_bots, name)
  File "C:\Users\Vincent\Documents\Kahoot Spammer V2\flood.py", line 20, in joinKahoot
    pin_form['inputSession'].value == pin
TypeError: 'NoneType' object is not subscriptable

我做错了什么?

【问题讨论】:

  • name_form["username"].value == name 比较正确的语法还是你的意思=
  • @rosh 不管怎样,我仍然得到同样的错误。
  • 表示browser.get_form()返回了None,然后你尝试查找None["username"]失败了。
  • pin_form 和 name_form 都是 NoneType 对象。
  • @HughBothwell 我并不是要让你当场,因为我假设你对 robobrowser 不太了解,但是我将如何修复它以便 get_form() 返回一些东西?

标签: python


【解决方案1】:

您正在打开的页面https://kahoot.it/#/ 不包含HTML &lt;form&gt; 标记。您看到的表单是使用 Javascript 创建的,无疑是为了使用基本的 HTML 解析技术来击败 DoS 攻击。

这就是browser.get_form() 什么都不返回的原因。该函数试图返回一个robobrowser.forms.form.Form 的实例,它是一个HTML 表单的表示,但它找不到。

我怀疑您将无法让robobrowser 在此特定网站上做您想做的事。也不错。

【讨论】:

  • 我该如何填写该表格?
  • 我了解到selenium 模块将执行 Javascript 并为您提供可以解析的 HTML。
猜你喜欢
  • 1970-01-01
  • 2020-09-03
  • 1970-01-01
  • 1970-01-01
  • 2021-08-11
  • 1970-01-01
  • 2020-02-22
  • 2013-01-13
  • 1970-01-01
相关资源
最近更新 更多