вот код
import telebot
import service
import requests
import re
from correct import InstagramLinksCorrect
from bs4 import BeautifulSoup
import logging
class ParseHashes:
patterns=service.OldPatterns()
code_with_hash_pattern=re.compile(r'"code"[ ]*:[ ]*"{}"'.format(patterns.image_hash_pattern))
hash_pattern=re.compile(patterns.image_hash_pattern)
def get_hashes(self,page_source):
temp_result=re.findall(self.code_with_hash_pattern,page_source)
hashes = []
for code_with_hash in temp_result:
temp=re.findall(self.hash_pattern,code_with_hash)
code,hash=temp[0],temp[1]
hashes.append(hash)
return tuple(hashes)
def get_source_by_link(link):
links_tester=InstagramLinksCorrect()
if not links_tester.ImageLinkIsValid(link):
return None
page_source=requests.get(link).text
soup=BeautifulSoup(page_source,'html.parser')
for meta_tag in soup.find_all('meta'):
if meta_tag.get('property', None) == 'og:image':
return meta_tag.get("content", None)
def get_tuple_of_sources_by_account(link):
"""Класс выдает кортеж ссылок по ссылке на профиль."""
links_tester = InstagramLinksCorrect()
if not links_tester.AccountLinkIsValid(link):
return None
page_source = requests.get(link).text
parser=ParseHashes()
hashes=parser.get_hashes(page_source)
sources=[]
for hash in hashes:
source=get_source_by_link('http://instagram.com/p/{}'.format(hash))
sources.append(source)
return tuple(sources)
def get_links_from_message(message):
patterns=service.NewPatterns()
acc_reg=re.compile(patterns.account_link_pattern)
im_reg=re.compile(patterns.image_link_pattern)
account_links=re.findall(acc_reg,message)
image_links=re.findall(im_reg,message)
return account_links,image_links
bot=telebot.TeleBot(token=service.telegram_token)
@bot.message_handler(commands=['start', 'help'])
def handle_start_help(message):
bot.send_message(message.chat.id, service.welcome_message)
@bot.message_handler(content_types=['text'])
def handle_message(message):
account_links,image_links=get_links_from_message(message.text)
sources=[]
for account_link in account_links:
sources_by_account_link=get_tuple_of_sources_by_account(account_link)
sources.extend(sources_by_account_link)
for image_link in image_links:
source=get_source_by_link(image_link)
sources.append(source)
for i in range(len(sources)):
link=sources[i]
bot.send_message(message.chat.id,'<a href="{}">{}</a>'.format(link,i),parse_mode='HTML')
logger=telebot.logger
telebot.logger.setLevel(logging.DEBUG)
bot.polling(none_stop=True)
вот ошибка
2021-11-16 03:40:23,787 (util.py:93 WorkerThread2) DEBUG - TeleBot: "TypeError occurred, args=("'NoneType' object is not iterable",)
Traceback (most recent call last):
File "C:\Users\ArtlorD)\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 87, in run
task(*args, **kwargs)
File "c:\Users\ArtlorD)\Desktop\instagram-downloader-bot-master\main.py", line 73, in handle_message
sources.extend(sources_by_account_link)
TypeError: 'NoneType' object is not iterable
"
Traceback (most recent call last):
File "c:\Users\ArtlorD)\Desktop\instagram-downloader-bot-master\main.py", line 83, in
bot.polling(none_stop=True)
File "C:\Users\ArtlorD)\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 660, in polling
self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "C:\Users\ArtlorD)\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 722, in __threaded_polling
raise e
File "C:\Users\ArtlorD)\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\__init__.py", line 682, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\ArtlorD)\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 135, in raise_exceptions
raise self.exception_info
File "C:\Users\ArtlorD)\AppData\Local\Programs\Python\Python38\lib\site-packages\telebot\util.py", line 87, in run
task(*args, **kwargs)
File "c:\Users\ArtlorD)\Desktop\instagram-downloader-bot-master\main.py", line 73, in handle_message
sources.extend(sources_by_account_link)
TypeError: 'NoneType' object is not iterable
что делат?