
고쳐보려는 시도를 계속하고 있으나 해결에 어려움을 겪고 있습니다.
제가 건드릴 때 마다 새로운 오류가 나오고 있네요 ㅎㅎ
TypeError: 'NoneType' object is not subscriptable
SyntaxError: invalid syntax
IndentationError: unexpected indent
도전1.
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=pnt&date=20210829',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
#old_content > table > tbody > tr:nth-child(3) > td.title > div > a
movies = soup.select('#old_content > table > tbody > tr')
for movie in movies :
a = movie.select_one('td.title>div > a')
b_rank = soup.select_one('#old_content > table > tbody > tr')
for b_alt in b_rank :
b = b_alt.select_one('td:nth-child(1) > img')['alt']
point = soup.select_one('#old_content > table > tbody > tr')
for c_point in point :
c = c_point.select_one('td.point')
if a is not None:
title = a.text
rank = b
star = c
print(rank,title,star)
#old_content > table > tbody > tr:nth-child(2) > td:nth-child(1) > img
#old_content > table > tbody > tr:nth-child(2) > td.point
도전1.오류
Traceback (most recent call last):
File "C:/Users/super/OneDrive/Desktop/sparta/pythonprac/scraping ver0.1.py", line 23, in <module>
b = b_alt.select_one('td:nth-child(1) > img')['alt']
TypeError: 'NoneType' object is not subscriptable
종료 코드 1(으)로 완료된 프로세스
도전2.
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=pnt&date=20210829',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
#old_content > table > tbody > tr:nth-child(3) > td.title > div > a
movies = soup.select('#old_content > table > tbody > tr')
for movie in movies :
a = movie.select_one('td.title>div > a')
b_rank = soup.select_one('#old_content > table > tbody > tr')
for b_alt in b_rank :
b = b_alt?.select_one('td:nth-child(1) > img')['alt']
point = soup.select_one('#old_content > table > tbody > tr')
for c_point in point :
c = c_point.select_one('td.point')
if a is not None:
title = a.text
rank = b
star = c
print(rank,title,star)
#old_content > table > tbody > tr:nth-child(2) > td:nth-child(1) > img
#old_content > table > tbody > tr:nth-child(2) > td.point
도전2.오류
File "C:/Users/super/OneDrive/Desktop/sparta/pythonprac/scraping ver0.1.py", line 23
b = b_alt?.select_one('td:nth-child(1) > img')['alt']
^
SyntaxError: invalid syntax
종료 코드 1(으)로 완료된 프로세스
도전3 부터는 b에 집중하기 위해서 c를 제거 해서 진행했습니다.
도전3.
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=pnt&date=20210829',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
#old_content > table > tbody > tr:nth-child(3) > td.title > div > a
movies = soup.select('#old_content > table > tbody > tr')
for movie in movies :
a = movie.select_one('td.title>div > a')
b_rank = soup.select_one('#old_content > table > tbody > tr')
for b_alt in b_rank :
b = b_alt.img.select_one('td:nth-child(1) > img')['alt']
point = soup.select_one('#old_content > table > tbody > tr')
if a is not None:
title = a.text
rank = b
print(rank,title)
도전3.오류
File "C:/Users/super/OneDrive/Desktop/sparta/pythonprac/scraping ver0.1 serious .py", line 28
if a is not None:
^
IndentationError: unexpected indent
종료 코드 1(으)로 완료된 프로세스
참고 중인 사항
https://www.reddit.com/r/learnpython/comments/88e33b/web_scraping_typeerror_nonetype_object_is_not/
