Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract tweet from Twitter using Python Selenium

I have problems about extracting tweets from Twitter. As I extracting tweets with Python Selenium, after a while Twitter occurs "Can’t load page". To solve this, I wrote time.sleep() method after extract tweet. But after N times, it will occurs again. How can i solve it?

The code is below:

driver = webdriver.Chrome()

driver.get(URL)

while(counter != tweets_count):
        # Get tweets
        for i in range(1,6):
            context = driver.find_element(By.XPATH, "//*[@id='react-root']/div/div/div[2]/main/div/div/div/div[1]/div/div[3]/section/div/div/div[" + str(i) + "]")
            context_list = context.text.split("\n")
            context_list = context_list[4:-5]
            temp = ""

            for j in range(len(context_list)):
                temp += context_list[j]

            tweets.append(temp)
            
            time.sleep(3)
        
        # Scroll down to bottom
        driver.execute_script("window.scrollTo(" + str(first_height) + ", " + str(increase_amount) + ");")
        
        first_height = increase_amount
        increase_amount = increase_amount+increase_amount
        
        # Waiting until page loading completely
        time.sleep(7)
        
        counter += 1
        print(counter)

"Can’t load page!". But I want to expect N times works.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That may be caused with twitter announcing a strict cap on how many posts you can view per day (1000 for unverified users, 10000 for verified
(here))

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading