Python Forum
improving bot with pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
improving bot with pandas
#1
hey everyone, i'm trying to improve my instagram selenium bot with pandas.
i want him to add every url that he is visiting to a file and work only if the current url is in the file,
so he wont like and comment to posts on instagram that he allready liked.
another problem is that the file is erasing and re-write every time the program runs.
a part of the code is below, if you know how can i do it or you have improving suggestion i would love to hear.

def execute(self):
        before_moving_to_file = []
        df = pd.read_csv("instagram_liked_links.csv")

        for link in self.links:
            self.browser.get(link)
            currentUrl = self.browser.current_url
            before_moving_to_file.append(currentUrl)
            updated_user_df = pd.DataFrame(before_moving_to_file)
            updated_user_df.to_csv('instagram_liked_links.csv'.format(strftime("%Y%m%d-%H%M%S")), encoding='utf-8', index=False)            

            time.sleep(1)

            try:
                if currentUrl in df:
                    continue
                
            else:
                    self.browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
                    time.sleep(1)

                    self.comment()
                    time.sleep(2)
                    self.like()

                    self.price += 0.02
                    sleeptime = random.randint(18, 28)
                    time.sleep(sleeptime)
                    

            except Exception:
                continue
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are there any techniques for improving logloss? AlekseyPython 0 1,388 Mar-20-2021, 04:37 AM
Last Post: AlekseyPython
  Genetic Algorithm Tetris Python not improving Fanto88 0 1,683 Mar-06-2021, 09:16 PM
Last Post: Fanto88
  Improving A Mean Algorithm dwainetrain 1 2,649 Aug-05-2017, 07:58 PM
Last Post: dwainetrain

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020