<jupyter_start><jupyter_text>Answer 1.1<jupyter_code>#logging_in
from selenium import webdriver
driver=webdriver.Chrome("/Users/User/Web drivers/chromedriver")
driver.get("https://www.instagram.com/")

wait = WebDriverWait(driver, 10)
user= wait.until(EC.presence_of_element_located((By.NAME,"username"))) 
password=driver.find_element_by_name("password")

#fill up username and password
user.send_keys("SAMPLE USERNAME")
password.send_keys("<PASSWORD>")

login=driver.find_element_by_xpath('//button[@type="submit"]/div')
login.submit()

#turning off notification pop up which comes on logging in
notificatn_off=driver.find_element_by_class_name("HoLwm")
notificatn_off.click()
driver.maximize_window()<jupyter_output><empty_output><jupyter_text>Answer 2.1<jupyter_code>#fetching names of the Instagram Handles that are displayed in list after typing “food” 
search=driver.find_element_by_xpath('//input[contains(@class,"XTCLo")]')
search.send_keys("food")
time.sleep(3)

l=driver.find_elements_by_class_name("Ap253")
print("The names of the Instagram Handles that are displayed in list after typing “food” are :--->")
for i in l:
    print(i.get_attribute('innerHTML').strip('#'))<jupyter_output>The names of the Instagram Handles that are displayed in list after typing “food” are :--->
foodtalkindia
food_happened
__journey__with__food__
dilsefoodie
your_scrolling_stopper
_foodfiestaa_
food
delhifoodguide
food_lunatic
uzbek_food
food_belly11
1_colours_1
delhieater
foodinsider
food_and_makeup_lover
buzzfeedfood
indian_food_freak
indianfood_lovers
foodofchennai
pune_food_blogger
foodiesdelhite
lefoodtour
dillifoodjunkie
fityetfoodie
hungrypixel
mumbaifoodie
foodnetwork
foodlovers96
food
foodtalkprivilege
foodelhi
mumbaifoodjunkie
foodieveggie
Food Station
thehungrymumbaikar
yum_crunch
Food Square
food_travel_etc
foodporn
food.creative
foodallday365
what.blue.eats
foodsnobtv
foodiliciousmoments
foodiesofguwahati
foodiediana
delhi_foodaholic
salonikukreja
karanfoodfanatic
foodtalkbangalore
the_foodies_journal
foodisnirvana
foodphotography
bangalore_foodjunkies
eatagii
concentrate_on_food<jupyter_text>Answer 3.1<jupyter_code>#searching and opening so_delhi page
search=driver.find_element_by_xpath('//input[contains(@class,"XTCLo")]')

search.clear()

search.send_keys("<NAME>")
time.sleep(3)
so_delhi=driver.find_element_by_class_name("Ap253")
so_delhi.click()<jupyter_output><empty_output><jupyter_text>Answer 4.1<jupyter_code>#going back to homepage
driver.back()
#searching and opening so_delhi page
search=driver.find_element_by_xpath('//input[contains(@class,"XTCLo")]')

search.send_keys("<NAME>")
time.sleep(3)
so_delhi=driver.find_element_by_class_name("Ap253")
so_delhi.click()<jupyter_output><empty_output><jupyter_text>Answer 4.2<jupyter_code>#following so_delhi page
follow_so_delhi=driver.find_element_by_xpath('//button[contains(@class,"_5f5mN")]')
follow_so_delhi.click()

print("Followed So_Delhi")<jupyter_output>Followed So_Delhi<jupyter_text>Answer 4.3<jupyter_code>#unfollowing so_delhi page
unfollow_so_delhi=driver.find_element_by_xpath('//button[contains(@class,"_5f5mN")]')
unfollow_so_delhi.click()

unfollow=driver.find_element_by_xpath('//button[contains(@class,"aOOlW")]')
unfollow.click()

print("Unfollowed So_Delhi")<jupyter_output>Unfollowed So_Delhi<jupyter_text>Answer 5.1<jupyter_code>#going back to homepage
driver.back()
#searching and opening dilsefoodie page
search=driver.find_element_by_xpath('//input[contains(@class,"XTCLo")]')
search.send_keys("<PASSWORD>")
time.sleep(2)

wait = WebDriverWait(driver, 10)
dilsefoodie= wait.until(EC.presence_of_element_located((By.CLASS_NAME,"Ap253"))) 
dilsefoodie.click()

#opening recent post 
wait = WebDriverWait(driver, 10)
to_be_liked_dilsefoodie=wait.until(EC.element_to_be_clickable((By.XPATH,'//div[contains(@class,"v1Nh3 kIKUG")]/a')))
to_be_liked_dilsefoodie.click()

#clicking like and repeating it for first 30 posts
for i in range(30):
    wait = WebDriverWait(driver, 10)
    like= wait.until(EC.presence_of_element_located((By.XPATH,'//div[@class="QBdPU "]/span'))) 
                                              
    like.click()
    next=driver.find_element_by_class_name('coreSpriteRightPaginationArrow')
    next.click()
    
    

print("Liked the first 30 posts of dilsefoodie")<jupyter_output>Liked the first 30 posts of dilsefoodie<jupyter_text>Answer 5.2<jupyter_code>#going back to dilsefoodie page
driver.get("https://www.instagram.com/dilsefoodie/")
#opening recent post
wait = WebDriverWait(driver, 10)
to_be_unliked_dilsefoodie=wait.until(EC.element_to_be_clickable((By.XPATH,'//div[contains(@class,"v1Nh3 kIKUG")]/a')))
to_be_unliked_dilsefoodie.click()

#clicking unlike and repeating it for first 30 posts
for i in range(30):
    wait = WebDriverWait(driver, 10)
    unlike= wait.until(EC.presence_of_element_located((By.XPATH,'//div[@class="QBdPU "]/span'))) 
                                              
    unlike.click()
    next=driver.find_element_by_class_name('coreSpriteRightPaginationArrow')
    next.click()
    
print("UnLiked the first 30 posts of dilsefoodie")<jupyter_output>UnLiked the first 30 posts of dilsefoodie<jupyter_text>Answer 6.1<jupyter_code>#going back to homepage
driver.get("https://www.instagram.com/")
#searching and opening the profile
def search_and_open(profile):
    search=driver.find_element_by_xpath('//input[contains(@class,"XTCLo")]')
    search.clear()
    search.send_keys(profile)

    wait = WebDriverWait(driver, 20)
    open_page= wait.until(EC.presence_of_element_located((By.CLASS_NAME,"Ap253"))) 
    open_page.click()
    


#getting top 500 follower's username
def get_username(profile):
    search_and_open(profile)
    
    #clicking on followers button
    wait = WebDriverWait(driver, 20)
    followers_button =  wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT,"followers")))
    followers_button.click()
    time.sleep(4)
    
    userlist = []
    
    #finding element for the followers popup
    fBody  = driver.find_element_by_xpath("//div[@class='isgrP']")
    #getting 500 usernames
    while len(userlist) < 500:
        #extracting names using BeautifulSoup
        data = driver.page_source
        html_data = BeautifulSoup(data, 'html.parser')

        ul = html_data.find_all(class_ = 'd7ByH')
        
        for u in ul[len(userlist):]:
            if u.a.string not in userlist: 
                userlist.append(u.a.string)
            
        #scrolling
        driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)

        
    return userlist


users = get_username('foodtalkindia')

print('The usernames of the first 500 followers of foodtalkindia are:')
for i in range(500):
    print(i+1, users[i])

#going back to homepage
driver.get("https://www.instagram.com/")
#so_delhi
users_sodelhi = get_username('sodelhi')

print('The usernames of the first 500 followers of sodelhi are:')
for i in range(500):
    print(i+1, users_sodelhi[i])<jupyter_output>The usernames of the first 500 followers of sodelhi are:
1 fatimaaaaa_kh
2 pragsjosh
3 aslamba13
4 jack_your_thoughts
5 afzal5430
6 itsmfahad
7 niks1320
8 mii_tube_
9 talkaboutdelicious
10 pr_rupa_mishra
11 ridhiisehgal
12 vaibhavgar97
13 chillr05
14 nailzonebykanika
15 hxnia_khxn
16 lkanma
17 vikaschauhan_7
18 kirtigoyall
19 sharnehaa
20 quotesby0u
21 that.brown.girl__
22 sami.akhtar786
23 fooodgrams
24 sourabhsharma2048
25 rohanjeenwal_0111
26 morganr44
27 sparkling_gurlll
28 heyniharika
29 arushi__narang
30 shemingleshermind
31 rachi_goel
32 himanshutibre
33 null5216
34 the_odd_bud
35 souledcraft
36 nehagandhilatika
37 veer_ji_malai_chaap_wale_
38 baani.gupta2324
39 royal_banna_abhi
40 naturelover2731
41 sadhkarishma
42 aanandi17
43 sushantarora19
44 s.h.u.b.h9
45 amri.ta7118
46 ritugosain
47 m.ashfaq05
48 koushikkumarray9
49 adityazsupertramp
50 dr_naved
51 rathore.shweta_
52 _faiza_abbasi_
53 prachi1kiara
54 fun_and_foodstation
55 cute_arru988
56 shubhsood
57 _manvi_saini_
58 dr.s[...]<jupyter_text>Answer 6.2<jupyter_code>#going back to homepage
driver.get("https://www.instagram.com/")

def not_follow_me(profile):
    search_and_open(profile)
    
    wait = WebDriverWait(driver, 10)
    
    # Finding followers of “foodtalkindia” that I am following
    followed_by = wait.until(EC.element_to_be_clickable((By.XPATH, '//span[contains(@class, "tc8A9")]')))
    followed_by.click()
    
    fl = wait.until(EC.presence_of_all_elements_located((By.XPATH, '//a[contains(@class, "FPmhX")]')))

    data = driver.page_source
    html_data = BeautifulSoup(data, 'html.parser')

    followers_list = []

    fll = html_data.find_all(class_ = 'FPmhX')
    for f in fll:
        followers_list.append(f.string)
    
    #Finding all my followers 
    driver.back()
    
    my_profile = wait.until(EC.element_to_be_clickable((By.XPATH, '//span[contains(@class, "_2dbep qNELH")]')))
    my_profile.click()
    
    profile = wait.until(EC.element_to_be_clickable((By.XPATH, '//a[contains(@class, "-qQT3")]')))
    profile.click()
    
    time.sleep(5)
    
    no_of_followers = wait.until(EC.presence_of_element_located((By.XPATH, '//a[contains(@class, "-nal3 ")]')))

    data = driver.page_source
    html_data = BeautifulSoup(data, 'html.parser')

    n = html_data.find_all(class_ = '-nal3')
    num = int(n[1].span.string)
    
    my_followers = wait.until(EC.element_to_be_clickable((By.XPATH, '//a[contains(@class, "-nal3 ")]')))
    my_followers.click()
    
    userlist = []
    #finding element for the followers name popup
    fBody  = driver.find_element_by_xpath("//div[@class='isgrP']")
    
    
    while len(userlist) < num:
        #extracting names using BeautifulSoup
        data = driver.page_source
        html_data = BeautifulSoup(data, 'html.parser')

        ul = html_data.find_all(class_ = 'd7ByH')
        
        for u in ul[len(userlist):]:
            if u.a.string not in userlist: 
                userlist.append(u.a.string)
            
        #scrolling
        driver.execute_script('arguments[0].scrollTop = arguments[0].scrollTop + arguments[0].offsetHeight;', fBody)
        

            
    followers_list = set(followers_list)
    userlist = set(userlist)
    
    
    #Finding All the followers of “foodtalkindia” that I am following but those who don’t follow me
    ans = followers_list - userlist
    
    print('All the followers of “foodtalkindia” that I am following but those who don’t follow me are:')

    for user in ans:
        print(user)
        

not_follow_me('foodtalkindia')<jupyter_output>All the followers of “foodtalkindia” that I am following but those who don’t follow me are:
your_scrolling_stopper
shreya241990<jupyter_text>Answer 7.1<jupyter_code>#going back to homepage
driver.get("https://www.instagram.com/")
from selenium.common.exceptions import TimeoutException
    
def get_story(profile):
    search_and_open(profile)
    wait = WebDriverWait(driver, 10)
    time.sleep(5)
    try:
        #finding element for the story
        story = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[contains(@class, "RR-M- h5uC0")]')))
        
        data = driver.page_source
        html_data = BeautifulSoup(data, 'html.parser')

        c = html_data.find(class_ = 'CfWVH')
        h = int(c['height'])
        w = int(c['width'])
        #height and width different for the story viewed and not viewed
        if h == 208 and w == 208:
            print("You have already seen the story")

        elif h == 210 and w == 210:
            print("You have not seen the story")
            story.click()
            print("You are now seening the story")
            
        
        

    except TimeoutException:
        print("The user has no story")
    
 
    
driver.get("https://www.instagram.com/")
time.sleep(2)
find_story=get_story("coding.ninjas")<jupyter_output>You have already seen the story
{'fraction_non_alphanumeric': 0.10954773869346733, 'fraction_numerical': 0.027135678391959798, 'mean_word_length': 4.455002284148013, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 7, 'lorem ipsum': 0, 'www.': 7, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '334418', 'license': 'MIT', 'n_tokens_mistral': 4527, 'n_tokens_neox': 4249, 'n_words': 832, 'path': 'InstaBot 1.ipynb', 'repo_name': 'rachitgupta0007/Insta-Bot', 'size': '11950'}