최근에 저는 간단한 웹 크롤러를 만드는 작업을 시작했습니다. 두 번 반복 된 코드는 완벽하게 작동했지만 오류 예외 처리 기능을 사용하여 클래스로 변환하려고 시도했지만 더 이상 컴파일되지 않았습니다.웹 크롤러 클래스가 작동하지 않습니다.
import re, urllib
class WebCrawler:
"""A Simple Web Crawler That Is Readily Extensible"""
def __init__():
size = 1
def containsAny(seq, aset):
for c in seq:
if c in aset: return True
return False
def crawlUrls(url, depth):
textfile = file('UrlMap.txt', 'wt')
urlList = [url]
size = 1
for i in range(depth):
for ee in range(size):
if containsAny(urlList[ee], "http://"):
try:
webpage = urllib.urlopen(urlList[ee]).read()
break
except:
print "Following URL failed!"
print urlList[ee]
for ee in re.findall('''href=["'](.[^"']+)["']''',webpage, re.I):
print ee
urlList.append(ee)
size+=1
textfile.write(ee+'\n')
myCrawler = WebCrawler
myCrawler.crawlUrls("http://www.wordsmakeworlds.com/", 2)
그리고 여기에 생성 된 오류 코드가 있습니다.
Traceback (most recent call last):
File "C:/Users/Noah Huber-Feely/Desktop/Python/WebCrawlerClass", line 33, in <module>
myCrawler.crawlUrls("http://www.wordsmakeworlds.com/", 2)
TypeError: unbound method crawlUrls() must be called with WebCrawler instance as first argument (got str instance instead)
- 노트 괄호를 (당신은 또한 당신이 정의 된 다른 방법에 대해이 작업을 수행해야합니다.). – jonrsharpe
내가 그랬을 때이 오류가 반환되었습니다. –
TypeError : __init __()은 인수가 없습니다 (주어진 1 개) –