All Projects → lovit → naver_news_search_scraper

lovit / naver_news_search_scraper

Licence: other
검색어 기준으로 네이버뉴스와 댓글을 수집하는 파이썬 코드

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to naver news search scraper

papercut
Papercut is a scraping/crawling library for Node.js built on top of JSDOM. It provides basic selector features together with features like Page Caching and Geosearch.
Stars: ✭ 15 (-60.53%)
Mutual labels:  scraper
quoters
📝 Random quotes generator package. Available on npm and PyPi
Stars: ✭ 17 (-55.26%)
Mutual labels:  scraper
ttc subway times
A scraper to grab and publish TTC subway arrival times.
Stars: ✭ 40 (+5.26%)
Mutual labels:  scraper
extract-css
Extract all CSS from a webpage, packaged as a Now V2 Lambda
Stars: ✭ 23 (-39.47%)
Mutual labels:  scraper
naver movie scraper
네이버 영화 정보 및 사용자 작성 영화평/평점 데이터 수집기
Stars: ✭ 27 (-28.95%)
Mutual labels:  scraper
Whatsapp-Group-Contacts-Scraper
How to scrap whatsapp group contacts from https://web.whatsapp.com/
Stars: ✭ 65 (+71.05%)
Mutual labels:  scraper
Android-Apps-Downloader
📱 A tool to download android apps from Google Play Store and Xiaomi App Store (the famous Chinese Store).
Stars: ✭ 16 (-57.89%)
Mutual labels:  scraper
munich-scripts
Some useful scripts simplifying bureaucracy
Stars: ✭ 105 (+176.32%)
Mutual labels:  scraper
mongodb-scraper
Scraps for publicly accessible MongoDB instances and dumps user passwords
Stars: ✭ 33 (-13.16%)
Mutual labels:  scraper
html2rss-web
🕸 Generates and delivers RSS feeds via HTTP. Create your own feeds or get started quickly with the included configs.
Stars: ✭ 36 (-5.26%)
Mutual labels:  scraper
Episode-ReName
电视剧/番剧自动化重命名工具
Stars: ✭ 89 (+134.21%)
Mutual labels:  scraper
bot
Completely free and open-source human-like Instagram bot. Powered by UIAutomator2 and compatible with basically any Android device 5.0+ that can run Instagram - real or emulated.
Stars: ✭ 321 (+744.74%)
Mutual labels:  scraper
Zeiver
A Scraper, Downloader, & Recorder for static open directories.
Stars: ✭ 14 (-63.16%)
Mutual labels:  scraper
berlin corona cases
Scraper for the official dashboard with current Corona case numbers, traffic light indicators ("Corona-Ampel") and vaccination situation for Berlin.
Stars: ✭ 19 (-50%)
Mutual labels:  scraper
dolarPy
Checks USD/PYG exchange rate from several sites, with a calculator, RESTful API and a twitter bot
Stars: ✭ 45 (+18.42%)
Mutual labels:  scraper
the-weather-scraper
A Lightweight Weather Scraper
Stars: ✭ 56 (+47.37%)
Mutual labels:  scraper
TorScrapper
A Scraper made 100% in Python using BeautifulSoup and Tor. It can be used to scrape both normal and onion links. Happy Scraping :)
Stars: ✭ 24 (-36.84%)
Mutual labels:  scraper
scraper
Nodejs web scraper. Contains a command line, docker container, terraform module and ansible roles for distributed cloud scraping. Supported databases: SQLite, MySQL, PostgreSQL. Supported headless clients: Puppeteer, Playwright, Cheerio, JSdom.
Stars: ✭ 37 (-2.63%)
Mutual labels:  scraper
SocialInfo4J
fetch data from Facebook, Instagram and LinkedIn
Stars: ✭ 44 (+15.79%)
Mutual labels:  scraper
RPICovidScraper
scraper for Rensselaer Polytechnic Institute (RPI)'s Covid Dashboard
Stars: ✭ 12 (-68.42%)
Mutual labels:  scraper

Notice

최근 뉴스 스크랩이 되지 않는 현상을 발견하였습니다 (관련이슈 #3). 이 내용이 해결되면 이 notice 를 제거하겠습니다.

Install

Python 3 로 작성되었습니다. 아래의 패키지를 이용합니다.

  • beautifulsoup4 >= 4.7.1
  • requiests >= 2.14.2

설치는 git clone 으로 코드를 받거나 downloads 를 합니다.

Python 버전 이슈

Python 3.7.x 에서 일부 뉴스의 본문이 제대로 스크랩 되지 않는 이슈가 있습니다. 3.6.x 에서는 제대로 작동합니다.

BeautifulSoup4 버전 이슈

코드 작성 당시 BeautifulSoup4 의 버전이 4.6.x 이하였으며, 4.7.x 에서 작동하지 않는 부분이 있었습니다 (Issue #1 참고). 이 부분이 수정되었으니, 4.7.x 이후의 버전을 쓰시는 분은 git pull 을 한 번 하시기 바랍니다 (작성일 2019.02.02 23:20)

Usage

실행 코드는 Python 으로 py 파일을 실행합니다. naver_news_search_crawler 폴더로 이동합니다.

python searching_news_comments.py --verbose --debug --comments

searching_news_comments.py 파일을 실행하면 output 폴더에 뉴스와 댓글이 저장됩니다. 이 파일은 몇 가지 arguments 를 제공합니다.

argument name default value note
--root_directory ../output/ 수집된 뉴스와 댓글의 저장 위치
--begin_date 2018-10-26 yyyy-mm-dd 형식으로 입력되는 데이터 수집의 첫 날
--end_date 2018-10-28 yyyy-mm-dd 형식으로 입력되는 데이터 수집의 마지막 날
--sleep 0.1 네이버 뉴스 사이트에 부하를 주지 않기 위한 여유시간. 단위는 초. 이 시간이 짧으면 네이버로부터 공격성 접근으로 인식되어 접속이 차단될 수 있습니다
--header None news 파일과 저장 폴더의 이름입니다. 아래에서 자세히 이야기합니다
--query_file queries.txt 질의어가 입력된 텍스트 파일. 한 줄에 하나의 단어를 입력합니다
--debug False --debug 입력 시 True, 각 일자별로 3 페이지의 뉴스와 댓글만 수집합니다
--verbose False --verbose 입력 시 True, 진행 상황을 자세히 보여줍니다
--comments False --comments 입력 시 True, 각 뉴스에 해당하는 댓글을 함께 수집합니다

수집된 데이터는 날짜별로 구분되어 각각 텍스트 파일로 저장됩니다. 이를 하나의 파일로 병합하기 위해서 다음의 스크립트를 실행하면 됩니다. 예시 데이터의 ../output/2019-01-14_05-31-08/economy 내에 있는 뉴스 기사와 뉴스 기사 인덱스, 댓글은 각각 다음의 파일에 저장됩니다. ../output/2019-01-14_05-31-08/economy.txt, ../output/2019-01-14_05-31-08/economy.index, ../output/2019-01-14_05-31-08/economy.comment.txt

python merging_scrap_results.py --directory ../output/2019-01-14_05-31-08/economy

Query file 구성

질의어가 담긴 query_file (예시 코드의 query.txt) 은 세 가지 형태로 구성할 수 있습니다.

첫째는 질의어만을 입력하는 것으로 외교만 입력하면 0 이라는 폴더에 기본 날짜인 begin_date 부터 end_date 사이의 기사를 수집합니다.

둘째는 질의어와 저장 폴더 이름을 지정하는 것으로, 경제economic 이라는 폴더에 기본 날짜인 begin_date 부터 end_date 사이의 기사를 수집합니다.

셋째는 질의어, 저장 폴더 이름, 기사 수집과 종료 날짜를 모두 기록하는 것으로, 기본 날짜와 관계 없이 2018-01-01 부터 2018-01-03 사이의 기사를 수집합니다.

외교
경제	economic
사회	social	2018-01-01	2018-01-03

Directory structure

기본 arguments 를 기준으로 설명합니다. 수집된 데이터의 기본 저장 위치는 ../output/ 입니다.

header 를 입력하면 output 폴더 아래에 header 의 이름으로 폴더가 생깁니다. diplomacy 폴더는 --header diplomacy 를 입력한 경우입니다. diplomacy 아래에는 query term 의 순서에 따라서 0 부터 폴더가 생성됩니다. 그 아래에 news 와 comments 폴더가 생성되며, news 폴더 아래에는 각 일자별 뉴스 (.txt) 와 뉴스의 인덱스 (.index) 파일이 생성됩니다. comments 에는 댓글이 존재하는 기사의 댓글이 tap 으로 분리되는 tsv 파일 형식으로 저장됩니다.

header 를 입력하지 않을 경우 스크립트를 실행시킨 시각 (초 단위까지)으로 폴더가 생성됩니다. 이때는 뉴스와 인덱스 파일에 header 가 붙지 않습니다.

--| naver_news_search_crawler
--| output
    --| diplomacy
        --| 0
            --| news
                --| 2018-10-26_diplomacy.txt
                --| 2018-10-26_diplomacy.index
            --| comments
                --| 001-0010429592.txt
                --| 001-0010429850.txt
                --| ...
    --| 2018-10-29_18-52-27
        --| 0
            --| news
                --| 2018-10-26.txt
                --| 2018-10-26.index
            --| comments
                --| 001-0010429592.txt
                --| 001-0010429850.txt
                --| ...

News 파일 구조

2018-10-26[_header].txt 로 명명되어 있으며, 한 줄이 하나의 뉴스기사이고 한 뉴스기사 내 줄바꿈은 두 칸 띄어쓰기로 구분됩니다.

Index 파일 구조

2018-10-26[_header].index 명명되어 있으며, 한 줄이 하나의 뉴스기사의 인덱스입니다. 2018-10-26[_header].txt 파일과 줄 단위로 같은 기사를 지칭합니다.

index 파일은 네 가지 정보로 구성된 tap separated value (tsv) 형식입니다. 첫줄에 header 가 없습니다.

column example note
key 052/2018/10/01/0001199008 언론사ID / yy / mm / dd / 기사ID
카테고리 이름 (혹은 번호) 104 104 번 뉴스 카테고리
기사 작성 시각 2018-10-01 23:52 혹은 최종 수정 시각. 때로 포멧이 일정하지 않은 경우가 있음
기사 제목 . 기사 제목

Comments 파일 구조

001-0010429592.txt 은 10-26 에 작성된 (언론사=001, 뉴스기사=0010370550) 의 리뷰로 tap 구분으로 이뤄진 csv 파일 입니다.

이 파일의 첫줄은 column head 입니다.

언제부터인지는 확인하지 못했지만, 댓글 등록자 아이디의 해쉬값은 더이상 return 되지 않습니다. 이 경우, 별표로 뒷부분이 마스킹 된 사용자 이름을 가져오도록 수정하였습니다.

column example note
comment_no 1514778615 댓글 고유 아이디
user_id_no 6EVlK 댓글 등록자 아이디의 해쉬값. 혹은 해쉬값이 제공되지 않을 경우 끝의 글자가 마스킹된 사용자 이름
contents 좋은 방향으로 얘기 잘 되었으면.. 댓글 내용
reg_time 2018-10-28T23:41:26+0900 댓글 등록 시각
sympathy_count 0 댓글 공감 수
antipathy_count 0 댓글 비공감 수
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].