티스토리 뷰

저번편에 이어서 Instagram 크롤링을 계속 해보자


먼저 할 일은 chrome process를 hidden으로 실행하는 것.

이것에 대한 정보는 거진 https://beomi.github.io/2017/01/20/HowToMakeWebCrawler/ 에서 다 얻어왔다.


아주 단순하다. chromedriver의 attribute에 headless를 추가하면 끝.

거기다가 span 태그를 통해 읽어온 '태그 갯수'에서 text만 추출하는 코드를 추가했다.


from bs4 import BeautifulSoup
import selenium.webdriver as webdriver

url = "https://www.instagram.com/explore/tags/jmt/"
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('disable-gpu')
driver = webdriver.Chrome('chromedriver', chrome_options=options)
driver.get(url)

soup = BeautifulSoup(driver.page_source, "html.parser")
tag = soup.find("span",{"class": "g47SY "})
count = tag.text
print(count)

https://github.com/100lab/poc_crawling_insta/commit/506a054324bc4144b5117dfbff59a53b18d0b3cc


다음번에는 restful server를 하나 만들어서, request가 올 경우 위의 값을 return해주는 api를 하나 만들어보자.


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
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
31
글 보관함