Recently have found a tiktok account I want personal notifications from when he posts a vid so I'm using BeautifulSoup plus requests to scrape the data and smtplib to get the notification.
It worked perfectly for 16 hours non stop with no error, Then it suddenly started giving the 'method' object is not subscriptable. Really don't know where the error is since the IP haven't been blocked and If I try to print the page all the page is printed. The error I'm getting is :
Traceback (most recent call last):
File "likes.py", line 44, in <module>
check:likes()
File "likes.py", line 14, in check_likes
converted_likes=float(title[0:4])
TypeError: 'method' object is not subscriptable
My script is:
import requests
from bs4 import BeautifulSoup
import smtplib
import time
import datetime
def check_likes():
URL = 'https://www.tiktok.com/@uchiha_johnzmen?'
headers = {"user-agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'}
page=requests.get(URL, headers=headers);
soup = BeautifulSoup(page.content, 'html.parser');
now=datetime.datetime.now()
title = soup.find(title="Likes").get_text()
converted_likes = float(title[0:4])
original_likes=1476
print (title.strip())
print (now.hour,':',now.minute)
if(converted_likes>original_likes):
send_mail()
time.sleep(1800)
original_likes=converted_likes
print (original_likes)
def send_mail():
server=smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login('','')
subject = 'nuevo video, run bitch'
body = ''
msg = f"Subject: {subject}\n\n{body}"
server.sendmail(
'@gmail.com',
'@gmail.com',
msg
)
print ('email sent')
server.quit()
while True:
check_likes()
time.sleep(15)
Would really use a helping hand since I don't understand why the number of likes is a non-sucrpitable object or why it stopped working after so many hours.