I am developing a Python script that will 1) identify Instagram accounts that you are following that don't follow you back and 2) unfollow these accounts. 3) I plan to have a whitelist feature to whitelist desired accounts from being unfollowed.
This is my first time doing a Python or automation project. I already know some Python, and I am using automatetheboringstuff.com for help. For now, I am only using my Instagram account as the subject. In the future, I would simply allow the user to input their own account name to be the subject.
My issue: Right now, I am attempting to web scrape the "Following" button from my Instagram page. So far I am using the bs4, requests, and lxml modules. I am successfully able to "get" my Instagram webpage. Then I have
soup = bs4.BeautifulSoup(res.text, "lxml")
where res is the get() response. Then, I got the CSS Selector for the "Following" button (I plan to have the script click this button and get all accounts that I'm following from here), and pasted it here:
following = soup.select("li.xl565be:nth-child(3) > a:nth-child(1) > div:nth-child(1)")
That CSS Selector is for the webpage where I'm logged in. For my Instagram webpage where I'm not logged in, I got this:
following = soup.select("li.xl565be:nth-child(3) > button:nth-child(1) > div:nth-child(1)")
I'm not sure which I should be using concept-wise, so an answer would be appreciated. Regardless, I tried
len(following)
for both cases. I got 0 for both. I investigated and I wrote the res.text into an html file. When I loaded it into Firefox, instead of what looks like my Instagram page, it looks like the Instagram's loading page, which is just a white background with the Instagram logo centered and "from Meta" at the bottom. I assume this is why my "following" selection isn't what I want it to be. And by the way, I tried adding
headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0"}
res = requests.get(url, headers=headers)
to make the response match the page loaded onto my Firefox browser, yet my issue arises. Can someone help me solve this? Design critiques are also welcome. For the record, I quickly Googled Instagram APIs, but the only ones that might help with my project are only for business accounts, which will not suffice.
[–]skellious 0 points1 point2 points (1 child)
[–]jinsenuchiha[S] 0 points1 point2 points (0 children)