2022. 6. 8. 11:22ㆍ골아픈퀀트/코딩
https://github.com/jknaudt21/Option-Scraper-BlackScholes
GitHub - jknaudt21/Option-Scraper-BlackScholes: Repo for scraping option data required for the Black Scholes model. Data is scra
Repo for scraping option data required for the Black Scholes model. Data is scraped from S&P500 companies - GitHub - jknaudt21/Option-Scraper-BlackScholes: Repo for scraping option data requir...
github.com
최근 딥러닝 프로젝트를 진행하면서 옵션 데이터가 필요했다
인터넷 서칭을 하다가 위 Option-Scraper Github를 발견했으나...

HA-HA 그러면 그렇지 삶은 언제나 쉽지 않다
자 드가자-

NoneType이 children이라는 오브젝트를 가지고 있지 않다니..!
그렇다면 문제는 HTML을 긁어오는 부분에서 생긴 것이다
해당 코드는 HTML을 requests 모듈로 긁어왔는데
최근에는 HTML을 requests로 긁으면 주요 내용을 받아올 수 없는 문제가 있다
따라서 requests 모듈을 selenium으로 치환했다
selenium 이용법은 나중에 따로 포스팅하려고 한다
어쨌든 selenium을 이용하니 option data crawling이 잘 수행되었다


이런식으로 순회하면서 데이터를 수집한다
해당 코드는 S&P500의 옵션 데이터를 수집한다

데이터는 Yahoo Finance 개별 종목의 Option Tab에서 수집된다

수집된 데이터의 모습이다
해당 코드를 통해 약 6000개 정도의 옵션 데이터를 얻을 수 있었다
코드를 Github Gist에 올려놓았다
https://gist.github.com/slayerzeroa/60de55b96db6a47acaffd661012ecdb1
option_scraper.py
GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
혹시 몰라 CSV 파일도 함께..