-
카테고리
-
세부 분야
데이터 분석
-
해결 여부
미해결
Yahoo Finance에서 URL 가져오기
22.07.20 09:40 작성 조회수 397
1
이 강의를 듣고 나면 네이버금융 뿐만 아니라 다른 웹 스크래핑도 가능할 것이라 하셨는데, 처음부터 너무 막히니 속상하네요. 스크립트는 다음과 같습니다.
import pandas as pd
from bs4 import BeautifulSoup as bs
url = f"https://finance.yahoo.com/quote/YM%3DF/history?p=YM%3DF"
table = pd.read_html(url)
response = requests.get(url, headers = headers)
html = bs(response.text)
table = html.select("table")
temp = pd.read_html(str(table))
temp[0]
여기서 url부터 인식을 못하고 HTTPError가 뜹니다. 해결방법이 있을까요?
HTTPError: HTTP Error 404: Not Found
답변을 작성해보세요.
0
박조은
지식공유자2022.07.20
import pandas as pd
from bs4 import BeautifulSoup as bs
url = f"https://finance.yahoo.com/quote/YM%3DF/history?p=YM%3DF"
table = pd.read_html(url) <= 이 부분 제거가 필요합니다.
response = requests.get(url, headers = headers)
html = bs(response.text)
table = html.select("table")
temp = pd.read_html(str(table))
temp[0]
1) headers 가 있는데 다른곳에서 선언해 준것인가요?
2) 오류가 나는 문장이 중간에 있으니 한 줄 한 줄 해보세요.
import requests
import pandas as pd
from bs4 import BeautifulSoup as bs
headers = {"user-agent": "Mozilla/5.0"}
url = f"https://finance.yahoo.com/quote/YM%3DF/history?p=YM%3DF"
response = requests.get(url, headers = headers)
html = bs(response.text)
table = html.select("table")
temp = pd.read_html(str(table))
temp[0]
잘 가져와집니다.
답변 1