편집 기록

편집 기록
  • 프로필 정영훈님의 편집
    날짜2018.08.27

    웹에서 가져온 html 테이블을 파이썬에서 csv 파일로 만드는 방법


    https://en.wikipedia.org/wiki/Comparison_of_text_editors에 있는 첫 번째 테이블(list of text editors)을 가져와서 csv 파일로 만드는 연습을 하고 있습니다.

    아래와 같이 파이썬 코드를 만들었고,

    import csv
    from urllib.request import urlopen
    from bs4 import BeautifulSoup
    
    html = urlopen("https://en.wikipedia.org/wiki/Comparison_of_text_editors")
    bs0bj = BeautifulSoup(html, "html.parser")
    
    table = bs0bj.findAll("table", {"class":"wikitable"})[0]
    rows = table.findAll("tr")
    csvFile = open("../files/editors.csv", 'wt')
    writer = csv.writer(csvFile)
    
    try:
        for row in rows:
            csvRow = [ ]
            for cell in row.findAll(['td', 'th']):
                csvRow.append(cell.get_text())
            writer.writerow(csvRow)
    
    finally:
        csvFile.close()
    

    이렇게 에러가 났습니다.

    FileNotFoundError Traceback (most recent call last) in () 10 table = bs0bj.findAll("table", {"class":"wikitable"})[0] 11 rows = table.findAll("tr") ---> 12 csvFile = open("../files/editors.csv", 'wt') 13 writer = csv.writer(csvFile) 14

    FileNotFoundError: [Errno 2] No such file or directory: '../files/editors.csv'

    파이썬에서 csv 파일을 만들 수 있는 것으로 아는데, 어디에 문제가 있는 것인지 도움 부탁 드립니다.

  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.08.26

    웹에서 가져온 html 테이블을 파이썬에서 csv 파일로 만드는 방법


    https://en.wikipedia.org/wiki/Comparison_of_text_editors에 있는 첫 번째 테이블(list of text editors)을 가져와서 csv 파일로 만드는 연습을 하고 있습니다.

    아래와 같이 파이썬 코드를 만들었고,

    import csv from urllib.request import urlopen from bs4 import BeautifulSoup

    html = urlopen("https://en.wikipedia.org/wiki/Comparison_of_text_editors") bs0bj = BeautifulSoup(html, "html.parser")

    table = bs0bj.findAll("table", {"class":"wikitable"})[0] rows = table.findAll("tr") csvFile = open("../files/editors.csv", 'wt') writer = csv.writer(csvFile)

    try: for row in rows: csvRow = [ ] for cell in row.findAll(['td', 'th']): csvRow.append(cell.get_text()) writer.writerow(csvRow)

    finally: csvFile.close()

    이렇게 에러가 났습니다.

    FileNotFoundError Traceback (most recent call last) in () 10 table = bs0bj.findAll("table", {"class":"wikitable"})[0] 11 rows = table.findAll("tr") ---> 12 csvFile = open("../files/editors.csv", 'wt') 13 writer = csv.writer(csvFile) 14

    FileNotFoundError: [Errno 2] No such file or directory: '../files/editors.csv'

    파이썬에서 csv 파일을 만들 수 있는 것으로 아는데, 어디에 문제가 있는 것인지 도움 부탁 드립니다.