summaryrefslogblamecommitdiffstats
path: root/skripti/4chan-thread-dl.py
blob: f1e2717373b0f5da6231b590f7498731e6831028 (plain) (tree)
1
2
3
4
5
6
7
8







                                                                                           








                                                                                                                
#!/usr/bin/python3
from bs4 import BeautifulSoup
from requests import get
from sys import argv
if len(argv) != 3:
	raise Exception("prvi arg je url do threada, drugi arg je končnica, recimo .webm")
s = BeautifulSoup(get(argv[1]).content, "html.parser")
for a in s.find_all("a"):
	if a.attrs["href"].endswith(argv[2]):
		fn = None
		if "title" in a.attrs and "/" not in a.attrs["title"]:
			fn = a.attrs["title"]
		elif "/" not in a.getText() and ("class" not in a.attrs or "fileThumb" not in a.attrs["class"]):
			fn = a.getText()
		if fn is not None:
			print(fn)
			open(fn, "wb").write(get("http:" + a.attrs["href"]).content)