강의

멘토링

커뮤니티

Inflearn Community Q&A

burce's profile image
burce

asked

[Renewed] Python Introduction and Web Scraping Basics Bootcamp [Python, Web, Data Understanding Fundamentals] (Updated)

크롤링 관련하여 soup.find 차이점, error 질문

Resolved

Written on

·

196

0

import requests

from bs4 import BeautifulSoup

res = requests.get('https://news.v.daum.net/v/20170615203441266')

soup = BeautifulSoup(res.content, 'html.parser')

mydata1 =  soup.find('p', attrs={'dmcf-pid':"nzh7QZekII",  'dmcf-ptype':'general'})

print(mydata1.get_text())

mydata2 = soup.find('p', dmcf-pid='nzh7QZekII', dmcf-ptype='general' ) 

----------------------------------------------------------------------------------------

error :

File "<ipython-input-40-9918cd039826>", line 10
    mydata2 = soup.find('p', dmcf-pid='nzh7QZekII', dmcf-ptype='general' )
                            ^
SyntaxError: keyword can't be an expression

----------------------------------------------------------------------------------------

안녕하세요 강사님 다름이아니라 위 코드내용에서 

mydata1 처럼 attrs={ } 형식에서는 err가 나진않지만 

mydata2 는 error 를 발생합니다

두개의 차이점에대해서 혹시 어떤부분을 놓치고 있는 걸까요?

python웹-크롤링

Answer 1

0

funcoding님의 프로필 이미지
funcoding
Instructor

안녕하세요. 속성과 속성값으로 체크하실 때에는 attrs={} 형식을 쓰셔야 합니다. id만 예외적으로 id='아이디값' 형태가 가능한 것이라서요. 감사합니다.~~~

burce's profile image
burce

asked

Ask a question