Answer the question
In order to leave comments, you need to log in
Why doesn't it find the .group attribute?
Why doesn't it find the attribute in this code? Please tell me how to fix the error
from telethon import TelegramClient, events, sync
import re
import webbrowser
import time
from bs4 import BeautifulSoup
api_id = 76675487
api_hash = "8c86a1764611d55565d8fddf49b181bd3"
client = TelegramClient('anon', api_id, api_hash)
client.start()
dlgs = client.get_dialogs()
for dlg in dlgs:
if dlg.title == 'LTC Click Bot':
tegmo = dlg
client.send_message(tegmo, '/visit')
while True:
second_m = str(client.get_messages(tegmo, limit= 2))
first_m = str(client.get_messages(tegmo, limit= 1))
g_1 = "'''" + second_m + "'''"
g_2 = "'''" + first_m + "'''"
url_1 = re.search(r'(https://.+?)\'', g_1).group(1)
url_2 = re.search(r'(https://.+?)\'', g_2).group(1)
if url_1 == url_2:
messages = (client.get_messages(tegmo, limit=1))
messages[0].click(2)
f = str(client.get_messages(tegmo, limit= 1))
g = "'''" + f + "'''"
url = re.search(r'(https://.+?)\'', g).group(1)
print(url)
webbrowser.open(url, 1)
time.sleep(15)
Traceback (most recent call last):
File "C:\Users\ars\PycharmProjects\telegram_bot_money\bot.py", line 26, in <module>
url = re.search(r'(https://.+?)\'', first_m).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
Answer the question
In order to leave comments, you need to log in
Because it is necessary not only to read the error message, but also to understand it.
They tell you in black and white English that you are trying to take an attribute (in this case, call a method) from an object of type None.
In other words, re.search() returned None to you.
And when does it happen? Open the documentation and read. In short, the string in first_m did not match the specified regular expression.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question