何か不足しているかどうかわかりませんが、これは私にこのエラーを与え続けます。私はいくつかの質問を読んだが、助けにはならないようだ。私は数日前にPythonを学び始めましたが、何が欠けていますか?私はエラーが発生した場合、何か他のものを試すためにエラーを除いてしようとしています。私はこれを別のコンピュータで動作させましたが、今は何らかの理由で動作していませんか?私はアナコンダとジュピターを使用しています。なぜこのNameErrorを取得していますか?私はこれを正しく使用していませんか?
import mechanize
from mechanize import ControlNotFoundError
import sys
from random import randint
import time
import csv
ipa=randint(1, 254)
ipb=randint(1, 254)
ip="131.156." + str(ipa) + "." + str(ipb)
ofile = "D:\\Downloads\\filename.csv"
url = "https://website.com"
br = mechanize.Browser()
br.set_handle_robots(False) # ignore robots
names=[]
i=0
entries=80
with open(ofile) as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
names.append((row[0],row[1]))
csvDataFile.close()
for name,email in names:
ipa=randint(1, 254)
ipb=randint(1, 254)
ip="131.156." + str(ipa) + "." + str(ipb)
br = mechanize.Browser()
br.set_handle_robots(False) # ignore robots
br.open(url)
br.select_form(nr = 0)
while True:
try:
br.form.find_control('Entries[registration_ip]').readonly = False
print ("Form found ")
break
except ControlNotFoundError:
print ("ControlNotFoundError")
br.open(url)
br.select_form(nr = 0)
br.form.find_control('Entries[registration_ip]').readonly = False
br.form.set_value(ip, 'Entries[registration_ip]')
br.form.set_value(name, 'Entries[full_name]')
br.form.set_value(email, 'Entries[email]')
time.sleep(randint(1, 110))
time.sleep(random())
res = br.submit()
print (name + " " + email)
content = res.read()
if (i > entries) : break
i+=1
time.sleep(randint(1, 200))
time.sleep(random())
with open("mechanize_results.html", "w") as f:
f.write(content)
エラー:
ControlNotFoundError Traceback (most recent call last)
<ipython-input-18-e095be0c9792> in <module>()
47 br.open(url)
48 br.select_form(nr = 0)
---> 49 br.form.find_control(
'Entries[registration_ip]').readonly =
False
50 br.form.set_value(ip, 'Entries[registration_ip]')
51 br.form.set_value(name, 'Entries[full_name]')
C:\Users\Donald\Anaconda2\lib\site-packages\mechanize\_form_controls.pyc in
find_control(self, name, type, kind, id, predicate, nr, label)
2329 raise ValueError(
2330 "at least one argument must be supplied to specify
control")
-> 2331 return self._find_control(name, type, kind, id, label,
predicate, nr)
2332
2333 # ---------------------------------------------------
C:\Users\Donald\Anaconda2\lib\site-packages\mechanize\_form_controls.pyc in
_find_control(self, name, type, kind, id, label, predicate, nr)
2422 description)
2423 elif not found:
-> 2424 raise ControlNotFoundError("no control matching " +
description)
2425 assert False
2426
ControlNotFoundError: no control matching name 'Entries[registration_ip]'
としてそれを参照見えるあなたのエラーコードを投稿してください、全体のトレースバック – 0TTT0
はあなたからその例外をインポートする必要があるよう0TTT0 –
@私のトレースバックが見えるが追加されましたそれが定義された場所。 –