Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from requests import get, post
- from json import loads
- from time import sleep
- def parse(thread, current_post, end):
- while 1:
- try:
- res = get(thread.replace(".html", ".json"))
- if res.status_code == 200:
- for post in loads(res.text)["threads"][0]["posts"][current_post:]:
- current_post = current_post + 1
- if current_post == end:
- print("Stop parser yopta")
- return 0
- if post["files"]:
- for file in post["files"]:
- if file["type"] == 6 or file["type"] == 10 or file["type"] == 2 or file["type"] == 4 or file["type"] == 1:
- tmp = get("https://2ch.hk" + file["path"]).content
- tmp_file = open(file["name"], "wb")
- tmp_file.write(tmp)
- tmp_file.close()
- sleep(10)
- elif res.status_code == 404:
- print("%s 404 not found." % thread)
- return 0
- except Exception as e:
- print("Fatal error: %s" % str(e))
- parse("https://2ch.hk/b/res/265324742.html", 0, 500)
Add Comment
Please, Sign In to add comment