티스토리 뷰

1초에 한번씩 google.com 페이지를 스크래핑 하는 크롤러를 파이썬(python)으로 만들어 보자



결과는 위와 같이 나오면 된다.


참고 포스트

2017/03/30 - [강의/Node.js] - 크롤링(Crawling)이란? 또는 파싱(Parsing)이란? 스크래핑이란?

2017/05/14 - [Language/Python] - 파이썬 크롤러 만들기

2017/05/10 - [Language/Python] - python thread로 3초에 1번씩 hello 출력하는 코드


정기적으로 크롤링 하는 코드를 만들어 보겠다.

1초에 한번씩 www.google.com을 호출 해서 데이터를 console 창에 출력하는 그런 프로그램이다.


소스코드는 아래와 같다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from urllib.request import urlopen
from threading import Thread
from time import sleep
 
def printResult():
    while True:
        print("hello")
        html = urlopen("http://www.google.com/")
        print(html.read())
 
        # if you want to change cycle from 1 second to 3 second please change here to '3'.
        sleep(1)
 
def main():
    th = Thread(target=printResult)
    th.demon = True
    th.start()
 
if __name__ == '__main__':
    main()
cs



아래 git 리포지토리에도 소스코드를 올려놓았다.

https://github.com/Kyeongrok/python_croller



동영상 강의도 찍었다


end.






공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함