Note

인스타그램 크롤링 (9) - 계정 팔로우, 팔로워, 게시글 본문

etc/Crawling

인스타그램 크롤링 (9) - 계정 팔로우, 팔로워, 게시글

알 수 없는 사용자 2022. 7. 14. 20:41
728x90
inf = {}

cnt = 0

MAX_SLEEP_TIME = 10

for i in tqdm(id):
    
    if cnt % 9 == 0:
        time.sleep(10)
    cnt += 1
    
    inf_info = {}
    
    try:

        driver.get("https://www.instagram.com/" + i)

        rand_value = np.random.randint(3, MAX_SLEEP_TIME)
        time.sleep(rand_value)

        body = driver.find_element_by_tag_name('body')
        html0 = driver.page_source # 현재 페이지 html
        html = bs(html0,'html.parser')
        

        # intro
        intro = html.find_all('span', {'class' : '_ac2a'})
        total_contents = intro[0].get_text()
        
        try:
            follower = intro[1]['title']
        except:
            follower = intro[1].get_text()
        try:
            follow = intro[2]['title']
        except:
            follow = intro[2].get_text()
            
        
        inf_info['total_contents'] = total_contents
        inf_info['follower'] = follower
        inf_info['follow'] = follow
        
        inf[i] = inf_info

     except:
            pass
        
inf_info = pd.DataFrame.from_dict(inf, 'index')
inf_info = inf_info.reset_index(drop = False)
inf_info.columns = ['insta_id', 'total_contents', 'follower', 'follow']
inf_info
Comments