Reputation: 21
I'm currently working on a selenium bot that gets a random english noun from a list of 1000 nouns, puts it in a site that gets similar instagram tags, then goes on instagram, logs into my account, and starts liking pictures with that hashtag, then starts the process all over again
My problem is the function that returns similar hashtags, this is the code for it:
def get_similar_tags(tag):
url = "https://top-hashtags.com/hashtag/" + str(tag).lower() + "/"
page = requests.get(url).text
parsed_page = BeautifulSoup(page, "html.parser")
parsed_page = parsed_page.find("div", class_="tht-tags")
text = parsed_page.text
hashtag = text.split(" ")
hashtag = [s.strip('#') for s in hashtag]
hashtag = hashtag.pop(len(hashtag) - 1)
return hashtag
When i try to print the hashtag variable inside of the function, then the output is filled with hashtags, which is exactly what i need.
When i use the function to assign the hashtag variable to another variable, like this:
foo = get_similar_tags(random_noun)
and then i do
print(foo)
i get absolutely nothing, not even an empty list, just an empty line. i've already tried assigning the value returned by the get_similar_tags function using a global variable, but that doesn't work either.
Any help would be really apprecciated, Thanks
Upvotes: 2
Views: 66
Reputation: 11942
hashtag = hashtag.pop(len(hashtag) - 1)
don't do that, try :
hashtag.pop(len(hashtag) - 1)
list.pop([i])
Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in the method signature denote that the parameter is optional, not that you should type square brackets at that position. You will see this notation frequently in the Python Library Reference.)
Upvotes: 2