파이썬 2.7을 사용하고 있습니다. 이 코드를 실행하려고하면 함수가 findPatTitle [i]를 인쇄하고 python이 "Index Error : list index of range"를 반환 할 때 문제가 발생합니다. 내가 13 번째 파이썬 튜토리얼에서 유튜브에이 코드를 가져갈거야, 그리고 난 꽤 코드가 동일하므로, 왜 내가 범위 문제를 얻을지 모르겠다 확신 해요. 어떤 아이디어?파이썬에서 기본 웹 스크래핑을 실행할 때 인덱스 오류가 발생했습니다.
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
import re
webpage = urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read()
patFinderTitle = re.compile('<title>(.*)<title>')
patFinderLink = re.compile('<link rel.*href="(.*)" />')
findPatTitle = re.findall(patFinderTitle,webpage)
findPatLink = re.findall(patFinderLink,webpage)
listIterator = []
listIterator[:] = range(2,16)
for i in listIterator:
print findPatTitle[i]
print findPatLink[i]
print "\n"
왜 BeautifulSoup를 가지고있을 때 정규식을 사용하여 html을 파싱합니까? o.O 정규식으로 HTML을 파싱해서는 안됩니다 ... http://stackoverflow.com/questions/590747/using-regular-expressions-to-parse-html-why-not – naeg