생활
파이썬 코드 분석부탁드립니다.
뉴스크롤링 코드를 공부하고있습니다.
아래코드는 특정게시판의 글을 가져오는 크롤링인데요
각 코드마다 어떠한 의미가 있는지, 왜 이렇게 만들었는지
설명 가능하신 코드 전문가분들의 답변 부탁드립니다.
코린이다보니, 코드를 봐도 제대로 이해가 잘안되네요
import requests
from bs4 import BeautifulSoup
url = 'https://finance.naver.com/news/news_list.naver?mode=RANK'
req = requests.get(url)
html = BeautifulSoup(req.content.decode('euc-kr', 'replace'), 'lxml')
newstitle = html.findall('ul', { 'class' : 'simpleNewsList' })
x = []
for link in newstitle :
for temp in link.findall('a') :
a = temp.get('href')
b = temp.get('title').replace('\xa0', '')
x.append('https://finance.naver.com/{},{}\n'.format(a, b))
output = open('output.csv', 'w', encoding = 'euc-kr')
output.writelines(x)
output.close()
아직 답변이 없어요.