Coder Social home page Coder Social logo

crawling's Introduction

학습목표

  1. SPM 활용
  2. Package를 포함하는 프로젝트
  3. 기본적인 웹 크롤링

1. SPM 활용

Pacakge 추가 및 import

image image image

2. Local SPM

Local Package 생성

image

Package.swift 파일 수정

image

build 해서 SwiftSoup 추가 확인

image

Local Package 추가하기

image image

Add Local... 버튼 클릭

image image

프로젝트 Target과 Local Package 연결

image image image

package import하여 사용하기

image

3. 기본적인 웹 크롤링

재학중인 대학교 학사 공지사항 게시판을 크롤링 http://board.sejong.ac.kr/boardlist.do?bbsConfigFK=335

image

  1. URL 설정
    guard let url = URL(string: "http://board.sejong.ac.kr/boardlist.do?bbsConfigFK=335") else{ throw Errors.urlError }
    let html = try String(contentsOf: url, encoding: .utf8)
  1. Parsing

Parsing 하고자하는 곳에 검사를 눌러 Selector 복사를 이용하면 쉽게 Select 할 태그를 얻을 수 있다.

image image image

복사 결과 : body > div.board-table.list > table > tbody > tr:nth-child(1)

tr 모두를 가져오면 되므로 select에서 tr까지 작성

    let contents : Document = try SwiftSoup.parse(html)
    let lines = try contents.select("body > div.board-table.list > table > tbody > tr")
  1. 출력
    for line in lines{
        try print(line.text())
    }

image

crawling's People

Contributors

sungmincho-kor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.