2020/09

    [Python] web scraping

    [Python] web scraping

    BeautifulSoup 라이브러리를 사용하면 간단하게 web scraping을 할 수 있다. BeautifulSoup 라이브러리는 HTML, XML을 분석해준다. 웹 사이트의 html을 scraping하기 위해서는 urllib 라이브러리도 함께 사용해야한다. 두 라이브러리를 함께 사용하여 웹 사이트의 html을 scraping할 수 있다. urllib option import urllib.request as request url = "https://990427.tistory.com" data = request.urlopen(url) urlopen() 함수는 url에 해당하는 웹 데이터를 가져온다. BeautifulSoup option from bs4 import BeautifulSoup html = '..

    [Python] 백준 2606

    [Python] 백준 2606

    BFS또는 DFS를 사용하는 그래프 탐색 문제다. 먼저, 입력받은 데이터는 딕셔너리로 구현하였다. 네트워크는 양방향 그래프 이므로 아래 코드와 같이 딕셔너리에 두 번 입력해야 한다. 그래프 구현 net = {} for i in range(n): a, b = map(int, input().split()) if a in net : net[a].append(b) else : net[a] = [b] if b in net : net[b].append(a) else : net[b] = [a] 같은 네트워크 상에 있는 컴퓨터를 검색하는 알고리즘은 BFS를 사용했다. visit에서 1을 빼면 1과 연결되어 있는 컴퓨터만 남게 되기 때문에 len(visit)-1을 결과로 출력했다. 전체코드 m = int(input())..