안경잡이개발자

728x90
반응형

  소스코드는 다음과 같습니다.


import urllib.request
from bs4 import BeautifulSoup


def main():

    sourcecode = urllib.request.urlopen("https://news.sbs.co.kr/news/newsflash.do?plink=GNB&cooper=SBSNEWS").read()
    soup = BeautifulSoup(sourcecode, "html.parser")

    list_href = []
    list_content = []

    for href in soup.find_all("div", class_="mfn_inner"):
        list_href.append("https://news.sbs.co.kr" + href.find("a")["href"])

    for i in range(0, len(list_href)):
        url = list_href[i]
        sourcecode = urllib.request.urlopen(url).read()
        soup = BeautifulSoup(sourcecode, "html.parser")
        list_content.append(soup.find("div", class_="text_area").get_text())

    print(list_href)
    print(list_content)


if __name__ == "__main__":
    main()






728x90
반응형

Comment +0