<jupyter_start><jupyter_text>1. Login to your Instagram Handle<jupyter_code>browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get('https://www.instagram.com/') #starting the webdriver sesion
wait = WebDriverWait(browser, 10) 
def login(): #login function
    time.sleep(4)
    name = browser.find_element_by_name("username") #locate the username column
    name.send_keys("username")
    time.sleep(1)
    password=browser.find_element_by_name("password") #locate the password column
    password.send_keys("password")
    password.submit()
    time.sleep(4)
    btn=browser.find_element_by_class_name("bIiDR") #locate the not now button
    btn.click()

login()<jupyter_output>[WDM] - Looking for [chromedriver 86.0.4240.22 linux64] driver in cache 
[WDM] - File found in cache by path [/home/deadwalker/.wdm/drivers/chromedriver/86.0.4240.22/linux64/chromedriver]<jupyter_text>2.Type for “food” in search bar and print all the names of the Instagram Handles that are displayed in list after typing “food”<jupyter_code>def search_food():   
    a=browser.find_element_by_xpath('//input[contains(@class,"XTCLo")]') #locate the search button
    a.send_keys('food') #passing food as search text
    time.sleep(3)       #sleep 3 sec.
    handles = browser.find_elements_by_xpath('//div[@class = "fuqBx"]/a["href"]') #fecting top food list hadles 
    food_list = []   
    for i in handles:
        if 'explore' in i.get_attribute('href'):#if explore present in link then it is hastags
            continue
        else:       
            s = i.get_attribute('href').split('/')  #https://www.instagram.com/foodtalkindia
            print(s[3]) # after split s= ['https:','','www.instagram.com','foodtalkindia']
            food_list.append(s[3])  #appending s[3] in food_list       
    a.clear() #clear the search box
search_food()<jupyter_output>_food_overdose_
yourfoodlab
food_quest824
foodnetwork
foodys
foodwarsofficial
food
the_food_saucer
foodie_incarnate
thisisdelhi
foodandwine
foodrush.recipe
foodyeating
foodistamysuru
foodporn
bongeats
foodranchi
bbcfood
ndtv_food
foodpandaindia
travellerritu
foodinsider
food_hotel_reviewer
wirallyfood
food.darzee
goodfoodau
food52
foodlty
wowfood5
ranchi_food_walks
fooddotcom
food._.sustenance
ziaflavia_foodnboobs
drooling__over__food
mumbaifoodie
delicioushealthyvideos
chaturvedineha10_
satshyaa
fao
foodsceneindia
foodbible
insight_food
food_mantraa
foodzoo2
fooodidilse
food_babe2.0
italyfoodprn<jupyter_text>3.Open profile of “So Delhi”<jupyter_code>def find_user():
    usr="<NAME>"
    text=browser.find_element_by_class_name("XTCLo") #Click on the search button
    text.clear() #clear the search column
    text.send_keys(usr) #Enter the text into the column
    time.sleep(2)
    find=browser.find_element_by_class_name("yCE8d") #click on the given id
    find.click()
    time.sleep(5)
    browser.back()

find_user()<jupyter_output><empty_output><jupyter_text>4.a)Start following the instagram handle of "sodelhi". Print a message if you are already following<jupyter_code>usr="<NAME>"
def follow_profile():
    text=browser.find_element_by_class_name("XTCLo") #Click on the search button
    text.clear() #clear the search column
    text.send_keys(usr) #Enter the text into the column
    time.sleep(2)
    find=browser.find_element_by_class_name("yCE8d") #click on the given id
    find.click()
    time.sleep(2)
    
    btn = browser.find_elements_by_css_selector('button')
    
    for i in btn:
        if i.text !='':
            if i.text=="Message":
                print("You are already following So Delhi")
                time.sleep(2)
                browser.back()
                break
            else:
                print("You are not following "+usr)
                btn=browser.find_element_by_class_name("_5f5mN") #click on the follow button
                btn.click()
                print("You are now following  "+usr)
                time.sleep(2)
                browser.back()
                break
    
follow_profile()<jupyter_output>You are not following So Delhi
You are now following  So Delhi<jupyter_text>4.b) After following, unfollow the instagram handle. Print a message if you have already unfollowed.<jupyter_code>usr="So Delhi"
def profile():
    text=browser.find_element_by_class_name("XTCLo") #Click on the search button
    text.clear() #clear the search column
    text.send_keys(usr) #Enter the text into the column
    time.sleep(2)
    find=browser.find_element_by_class_name("yCE8d") #click on the given id
    find.click()
    time.sleep(2)
    
    btn = browser.find_elements_by_css_selector('button')
    
    for i in btn:
        if i.text !='':
            if i.text=="Message":
                unfollow()
                break
            else:
                print("You have already Unfollowed So Delhi")
                time.sleep(2)
                browser.back()
                break

def unfollow():
    time.sleep(3)
    btn=browser.find_element_by_class_name("_5f5mN") #click on the follow button
    btn.click()
    time.sleep(3)
    btn = browser.find_elements_by_css_selector('button')
    for button_search in btn:
        if(button_search.text == 'Unfollow'):
            print("You are following "+usr)
            button_search.click()
            print("You have now unfollowed "+usr)
            time.sleep(2)
            browser.back()
            break
profile()<jupyter_output>You are following So Delhi
You have now unfollowed So Delhi<jupyter_text>5.a) Liking the top 30 posts of the ‘dilsefoodie'. Print message if you have already liked it.<jupyter_code>#liking the posts
search = browser.find_element_by_xpath('//div[contains(@class,"LWmhU")]/input')     #input box
search.send_keys('dilsefoodie')                                                    #sending keys
b = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'z556c')))            #searching sodelhi profile  
b.click()    
time.sleep(4)
post=browser.find_element_by_class_name("_9AhH0")
post.click()
for i in range(30):
    time.sleep(5)
    nexb=browser.find_element_by_class_name("_65Bje")
    like_btn = browser.find_element_by_xpath('//span[contains(@class,"fr66n")]/button')
    Check_ctn = browser.find_element_by_xpath('//span[contains(@class,"fr66n")]/button/*[name()="svg"]')
    if Check_ctn.get_attribute('aria-label') == 'Unlike':#checking status
        print("Already Liked the {}th Post".format(i+1))#for like button    
    else:
        like_btn.click()
    time.sleep(4)
    nexb.click()
close_btn = browser.find_element_by_xpath('//div[contains(@class,"BI4qX")]/button')                        # post close button
close_btn.click()
time.sleep(2)
tool=browser.find_element_by_class_name("oJZym")
tool.click()<jupyter_output>Already Liked the 1th Post
Already Liked the 2th Post
Already Liked the 3th Post
Already Liked the 4th Post
Already Liked the 5th Post<jupyter_text>Unliking the top 30 posts of the ‘dilsefoodie’. Print message if you have already unliked it.<jupyter_code>#Unliking the posts
search = browser.find_element_by_xpath('//div[contains(@class,"LWmhU")]/input')     #input box
search.send_keys('dilsefoodie')                                                    #sending keys
b = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'z556c')))            #searching sodelhi profile  
b.click()    
time.sleep(4)
post=browser.find_element_by_class_name("_9AhH0")
post.click()
for i in range(30):
    time.sleep(5)
    nexb=browser.find_element_by_class_name("_65Bje")
    like_btn = browser.find_element_by_xpath('//span[contains(@class,"fr66n")]/button')
    Check_ctn = browser.find_element_by_xpath('//span[contains(@class,"fr66n")]/button/*[name()="svg"]')
    if Check_ctn.get_attribute('aria-label') == 'Like':#checking status
        print("Already Unliked the {}th Post".format(i+1))#for like button    
    else:
        like_btn.click()
    time.sleep(4)
    nexb.click()
close_btn = browser.find_element_by_xpath('//div[contains(@class,"BI4qX")]/button')                        # post close button
close_btn.click()
time.sleep(2)
tool=browser.find_element_by_class_name("oJZym")
tool.click()<jupyter_output><empty_output><jupyter_text>Extract the usernames of the first 500 followers of ‘foodtalkindia’ and "sodelhi".<jupyter_code>u_ser=["foodtalkindia","sodelhi"]

for i in u_ser: #iterating over the user profiles
    search = browser.find_element_by_xpath('//div[contains(@class,"LWmhU")]/input') #input box
    search.send_keys(i)
    first_search = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'z556c'))) #first profile
    first_search.click()
    time.sleep(2)
    follower = browser.find_element_by_partial_link_text("follower")
    follower.click()
    time.sleep(4)
    followersList = browser.find_element_by_css_selector('div[role=\'dialog\'] ul')
    numberOfFollowersInList = len(followersList.find_elements_by_css_selector('li'))


    followersList.click()
    actionChain = webdriver.ActionChains(browser)
    while (numberOfFollowersInList < 500):
        actionChain.key_down(Keys.SPACE).key_up(Keys.SPACE).perform()
        numberOfFollowersInList = len(followersList.find_elements_by_css_selector('li'))

    followers = []
    for user in followersList.find_elements_by_css_selector('li'):
        userLink = user.find_element_by_css_selector('a').get_attribute('href')
        followers.append(userLink)
        if (len(followers) == 500):
            break
    print("----------------------------------------------------------------------------")        
    print("The top 500 followers of {} are:".format(i))
    print("----------------------------------------------------------------------------")        

    for i in followers:
        print(i.split("/")[3])

    browser.back()
    browser.back() #moving back to the main page<jupyter_output>----------------------------------------------------------------------------
The followers of foodtalkindia are:
----------------------------------------------------------------------------
arnav_mehraaa
thespicedlime
food_fetish_diaries
myfoodthela
ipoojaabairwa
ojusvni_kapur
sana1__0
_iam_umar_d
aasthasahdev20
namdevbailurkar
shbhatnagar
i_ts_v_a_n_s_h
almosteverythingggg
siyaksharma
mr_anno_afc
nahida_q1990
eats.ok
13jat_26
blu_view
s.m800_
damnitdam
iyaarjokar
_e.l.y.s.i.a.n_07
fernresidency
sidharthsaini63
i_m_praveenrawat
kapila_miglani
bareeranajam
chef.sau_ras
x_sameer_92
mr.prashanth007
aniketgurav4141
mr.rateria
bhavesh.pathade
smoker_sangam
rcmpinternational
the_food_philosophy25
foodrambler19
ekta_kunal
awara_azaad_aurat
officialfoodietiger
ohchewyindia
richa9942
santhu.krishnna
foodily_ever_after
noicelydonee
sauravsoos
acookingtour7
abhishekjain841989
___7596___
----------------------------------------------------------------------------
The followers of sodelhi are:
----[...]<jupyter_text>Now print all the followers of “foodtalkindia” that you are following but those who don’t follow you.<jupyter_code>search = browser.find_element_by_xpath('//div[contains(@class,"LWmhU")]/input') #input box
search.send_keys('<PASSWORD>')
first_search = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'z556c'))) #first profile
first_search.click()
time.sleep(2)
followers_button = wait.until(EC.presence_of_element_located((By.XPATH,'//a[contains(@class,"-nal3")]')))#follower button
followers_button.click()
flag = False
while True:
    p = browser.find_element_by_class_name('isgrP')         #follower page
    p.click()
    browser.find_element_by_tag_name('body').send_keys(Keys.END)                              #moving to end of page
    if flag == False:
        for i in range(500):
            browser.find_element_by_tag_name('body').send_keys(Keys.PAGE_UP)                  #make 6 time page up to remove first suggestion
            time.sleep(1)
        flag = True
    time.sleep(1)
    p = browser.find_element_by_class_name('isgrP')                                          #follwer page
    p.click()
    follower_list = browser.find_elements_by_xpath('//div[@class = "isgrP"]/ul/div/li')      #folllower list
    if len(follower_list) >= 500:
        break
li = []
j=0
names = []
for i in follower_list:
    data = BeautifulSoup(i.get_attribute('innerHTML'),'html')                            #alreday explained 
    li.append(data.a['href'].split('/')[1])
    names.append(data.a['href'].split('/')[1])
    j+=1
    if j==500:
        break
for i in names:
    print(i)<jupyter_output>gurawaprincy
anurag07___
_the_lost_monk
sushil.blink
iam_sanjanaa
basicallyjobless_
laiba.in
sonusaifi6122
santtosha
shariq_siddique78
shaliniagrawal_02
gudduyadav425
digging_dreams
artenstein_
kavnkia_sachdeva
priyankas.aroras
what_where_she_ate
suchismita403
the.painters.blog
the.opulent.nomad
dev.devdhar
itsishaniarora
vaibhav__chandhok
designby.rb
aakshisings
daudkhann
sumandagar3946
ss_thebongfoodies
dantani.raj.397
gujral_tanyaa
kascera_by_ritu
mr_danish_writes_
umf080
meristorieshai
kabir_rao0703
_aditya_aggarwal
___s.w.a.s.t.i.k.a___99
bhavisha200
ashm33t
deepakpandey129
mouniminne
nikitaagarwal63
_itz_akky_07_
mug_of_pens
ghosh_prerna
tusharsierra
manya.uppal16
alishash687
real_graphy_
saurabhdex
captions_gram
cromulent_asf
tan.veeer
mohdvaisar
quarantine_recipe
chaitanyamunjal
renikuntahasya
tanyakhanna96
drathore.____
officialarshkaur
ishika_khaneja_31
ciel_sombre_
sumitkumar826
sswadesh
garima.gupta8
iraagrawal
prashantrajput179
yashie_._._
bacchic_guy
reyes17jr
unique_ramg[...]<jupyter_text>Check the story of ‘coding.ninjas’.<jupyter_code>count=0
search = browser.find_element_by_xpath('//div[contains(@class,"LWmhU")]/input')      #input box  
search.send_keys('<PASSWORD>')
first_search = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'z556c')))  #fisrt profile
first_search.click()
print('Not checked the story yet')
time.sleep(2)
try:
    a = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'h5uC0')))
    if count==1:
        print("Already seen the Story.")
        time.sleep(2)
        browser.back()
    else:
        a = wait.until(EC.presence_of_element_located((By.CLASS_NAME,'_2dbep')))              #for story check button
        a.click()
        print("Seen the story")
        count+=1
        time.sleep(30) #minimum sleep time to see the maximum number of stories
        browser.back()
        browser.back()
    
except TimeoutException: #exception timeout
    print("User don't have a Story.")
    time.sleep(2)
    browser.back()

browser.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1309638388560429, 'fraction_numerical': 0.019043035886154268, 'mean_word_length': 3.3501794258373208, 'pattern_counts': {'":': 2, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '593377', 'license': 'MIT', 'n_tokens_mistral': 5168, 'n_tokens_neox': 4923, 'n_words': 971, 'path': 'Project Instabot-1 Rohan Raj.ipynb', 'repo_name': 'rohan1907/InstagramBot', 'size': '14556'}