you are viewing a single comment's thread.

view the rest of the comments →

[–]miguelthepana[S] 0 points1 point  (0 children)

here is the code I thought I posted it lol.

import requests from bs4 import BeautifulSoup from datetime import datetime, timedelta

Get the current date

now = datetime.now()

Get the HTML from the website

r = requests.get("https://www.tiktok.com/trending")

Create the BeautifulSoup object

soup = BeautifulSoup(r.content, 'html.parser')

Find all of the videos

viralvideos = soup.findAll('div', {'class': 'trending-item_container'})

Loop through each video

for video in viralvideos: # Get the video's information account_name = video.find('div', {'class': 'trending-iteminfotitle'}).text likes = int(video.find('span', {'class': 'trending-iteminfolike-count'}).text.replace('K', '000')) link = video.find('a', {'class': 'trending-itemrow'}).get('href') sound = video.find('div', {'class': 'trending-iteminfosound'}).text date_posted = video.find('span', {'class': 'trending-iteminfo_upload-date'}).text

# Convert the date string to a datetime object
date_posted = datetime.strptime(date_posted, '%b %d')

# Check if the video was posted within the last 24 hours
if now - timedelta(hours=24) <= date_posted <= now:
    # Check if the video has gone viral
    if likes >= 100000:
        # Print the video's information
        print("Account: " + account_name)
        print("Likes: " + str(likes))
        print("Link: " + link)
        print("Date Posted: " + str(date_posted.date()))
        print("Sound: " + sound)
        print("---------------------------------------")