0
Mac 및 BeautifulSoup에서 Python3.6을 사용하여 몇 가지 실험을하고 있습니다. URL에서 노래 가사를 스크랩하고 단일 변수에 일반 텍스트로 저장하는 간단한 프로그램을 작성하려고하지만 HTML 컨텐츠를 반복 할 수 없습니다.BeautifulSoup을 사용하여 목록을 반복 할 수 없습니다.
: 나는 다음과 같은 오류가all = all.text
을하려고하면 코드의 마지막 두 줄은, 또한
"List index out of range" Error
을 반환
import requests
import re
from bs4 import BeautifulSoup
r = requests.get("http://www.metrolyrics.com/juicy-lyrics-notorious-big.html")
c = r.content
all = soup.find_all("p",{"class":"verse"})
all[0:10]
for item in all:
print(item.find_all("p",{"class":"verse"})[0].text)
을 :
이
내가 실행하고 코드입니다AttributeError: ResultSet object has no attribute 'text'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
나는 이것이 단순해야한다고 생각하지만 더 이상 무엇을 해야할지 모릅니다.
감사
와우, 정말 간단했습니다. 고맙습니다! –