ich habe mein erstes kleines Python 3 Programm fertiggestellt, allerdings tut sich ein kleines Problem auf. Der Code an sich funktioniert, allerdings benötigt requests.get() sehr lange um an den HTML Code zu kommen. Gibt es eine Möglichkeit das zu beheben? Bei dem Programm handelt es sich um einen Tellonymcrawler.
Code: Alles auswählen
import os
import requests
from bs4 import BeautifulSoup
#Clear CMD Messages
def cls():
os.system('cls' if os.name=='nt' else 'clear')
#Calculate how many pages this profile has (Function)
def pagecount():
pages = soup.find_all('div', {"class": "col-xs-12 text-center top-margin-1"})
pages = pages[0].text.split(" ")
pages = round(int(pages[6]) / 6 + 0.3)
return pages
#Questioning and combining url
profile = input("Welches Profil moechtest du durchsuchen?\n")
word = input("Nach welchem Wort moechtest du suchen?\n")
cls()
url = "https://tellonym.me/%s" % (profile)
#Get HTML and start calculating the amount of profile pages
sauce = requests.get(url)
soup = BeautifulSoup(sauce.text, "html.parser")
pagecounter = pagecount()
tellname = soup.find_all('div', {"class": "displayname replaceEmoji"})
#Start scanning loop for tells with the given string
counter = 1
print(tellname[0].text.strip() + "'s Tellonym" + " | Suche nach String: " + word + "\n")
while counter <= pagecount():
url = "https://tellonym.me/%s?page=%i" % (profile, counter)
sauce = requests.get(url)
soup = BeautifulSoup(sauce.text, "html.parser")
tellquestions = soup.find_all('div', {"class": "panel-heading tell replaceEmoji "})
tellanswers = soup.find_all('div', {"class": "panel-body answer replaceEmoji "})
telltime = soup.find_all('div', {"class": "time float-right"})
tellcount = 0
while tellcount < len(tellquestions):
if word in tellquestions[tellcount].text.lower():
found = True
print("Frage: " + tellquestions[tellcount].text.strip())
print("Antwort: " + tellanswers[tellcount].text.strip())
print("Zeitraum: " + telltime[tellcount].text.strip())
print("\n")
tellcount += 1
counter += 1
if not 'found' in locals():
cls()
print("Es wurden keine Tells mit diesem String gefunden!")