threads_bs
von TRex- SNIPPET_TEXT:
-
- import bs4
- import requests
- import re
- import sys
- from timeit import timeit
- # HTML des "Netzwerk"-Unterforums
- dfde = requests.get("https://debianforum.de/forum/viewforum.php?f=30").text
- def parse(html):
- soup = bs4.BeautifulSoup(dfde, 'html.parser')
- threads = soup.select("ul.topiclist li.row")
- for thread in threads:
- title = thread.select("a.topictitle")[0].text
- username = thread.select("div.topic-poster a")[0].text
- answers = thread.find("dd", class_="posts").text
- if __name__ == "__main__":
- if "timeit" in sys.argv:
- timing_results = timeit(lambda: parse(dfde))
- print(timing_results)
- else:
- for thread in parse(dfde):
- print(thread)
Quellcode
Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN