hsnam95 / class2022Spring

130 stars 21 forks source link

URL 오류 질문 #17

Open hyesuun opened 2 years ago

hyesuun commented 2 years ago

안녕하세요 교수님 2021130907 정혜선입니다.

def test(CMPNM): URL = ('http://apis.data.go.kr/6430000/cbRecreationalFoodInfoService/' 'getRecreationalFoodInfo?' 'serviceKey=KUte%2B1a0lMg33Joa%2Bu5ovcX%2F3e%2F7mY8MYvtinzMjlJUetgUjZdZY%2BElYD6eL9akDvYlj0%2Fn3Na74Cy%2BKubHUzg%3D%3D' '&currentPage=1' '&perPage=10' '&CMPNM='+CMPNM+)

response = requests.get(URL) r = response.json() items = r['body']

SIGUN = [item['SIGUN'] for item in items] ADRES = [item['ADRES'] for item in items] TIME = [item['TIME'] for item in items] MENU = [item['MENU'] for item in items] MNMNU = [item['MNMNU'] for item in items] CMPNM = [item['CMPNM'] for item in items] TELNO = [item['TELNO'] for item in items]

SIGUN = pd.Series(SIGUN) ADRES = pd.Series(ADRES) TIME = pd.Series(TIME) MENU = pd.Series(MENU) MNMNU = pd.Series(MNMNU) CMPNM = pd.Series(CMPNM) TELNO = pd.Series(TELNO)

df = pd.DataFrame({'시군':SIGUN, '주소':ADRES, '운영시간':TIME, '메뉴':MENU, '메인메뉴':MNMNU, '상호':CMPNM,'전화번호':TELNO}) return df

File "", line 7 '&CMPNM='+CMPNM+) ^ SyntaxError: invalid syntax 이렇게 뜨는데 오류가 나는 이유를 잘 모르겠습니다...

hsnam95 commented 2 years ago

지금은 잘 되네요

JiaPark01 commented 2 years ago

7번 줄에 +CMPNM+에서 마지막 +를 빼주셔야 합니다.

+를 쓰는 이유는 해당 변수 앞과 뒤에 문자열이 있기 때문에 이어주기 위해 씁니다. 그래서 변수가 마지막에 올 때는 뒤에 이어줄 문자열이 없기 때문에 +CMPNM으로 끝내면 될 겁니다.

hyesuun commented 2 years ago

감사합니다!