728x90
반응형
res=rq.get("https://www.naver.com")
html = res.text
print(res.text)

soup = BeautifulSoup(html,'lxml')
soup.find_all('p')

list 타입으로 바꾸기
list_p = list(soup.find_all('p'))
list_p

type(list_p) #list

for i,j in enumerate(list_p): #숫자를 줌
print(i,j)

문제) 위 출력결과에서 br 태그가 있는것만 출력하기
strre=[]
for i,j in enumerate(list_p): #숫자를 줌
if 'br' in str(j):
print(i)
strre.append(j)

문제 ) br 태그를 제거하기
replace를 이용한다.
remover=[]
for i in strre:
temp = str(i)
temp=temp.replace('<br/>',' ')
remover.append(temp)

728x90
반응형