Skip to content

3장에서 가격과 주소 불러오는 코드에서 'HTTPError: HTTP Error 403: Forbidden' 에러 #100

@jjjjunn

Description

@jjjjunn

price = []
address = []

for n in df.index[:3]:
html = urlopen(df['URL'][n])
soup_tmp = BeautifulSoup(html, 'lxml')

gettings = soup_tmp.find('p', 'addy').get_text()

price.append(gettings.split()[0][:-1])
address.append(' '.join(price_tmp.split()[1:-2]))

코드 입력할때 HTTPError: HTTP Error 403: Forbidden 오류가 떠서

상단에
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0'}
req = Request(df['URL'][n], headers=headers)
html = urlopen(req)

코드를 같이 넣어서 진행했는데도 여전히 오류가 뜹니다.
어떻게 해결해야 하나요?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions