|
| 1 | +from bs4 import BeautifulSoup |
| 2 | +import requests |
| 3 | + |
| 4 | + |
| 5 | +def download(webcode): |
| 6 | + url = "https://www.westermann.de/webcode" |
| 7 | + payload = {'webcode': webcode} |
| 8 | + # Die Seite mit dem Webcode aufrufen und die Zielseite erfragen |
| 9 | + web = requests.post(url, data=payload, allow_redirects=False) |
| 10 | + location = web.headers['Location'] |
| 11 | + zieladresse = "https://www.westermann.de" + location |
| 12 | + # Die Zielseite aufrufen und den Link auf die Webressource erfragen |
| 13 | + web = requests.get(zieladresse) |
| 14 | + soup = BeautifulSoup(web.text, "html5lib") |
| 15 | + links = soup.find_all("a") |
| 16 | + ressource = "" |
| 17 | + for link in links: |
| 18 | + if "backend" in link["href"]: |
| 19 | + ressource = "https://www.westermann.de" + link["href"] |
| 20 | + # Die Seite mit der Ressource aufrufen, die Ressource herunterladen |
| 21 | + web = requests.get(ressource, allow_redirects=True) |
| 22 | + with open(f"{webcode}.doc", "wb") as f: |
| 23 | + f.write(web.content) |
| 24 | + |
| 25 | +def main(): |
| 26 | + # |
| 27 | + webcodes = ['SNG-22788-999', 'SNG-22788-990', 'SNG-22788-909', 'SNG-22788-100', 'SNG-22788-111', 'SNG-22788-110', |
| 28 | + 'SNG-22788-101', 'SNG-22788-001', 'SNG-22788-011', 'SNG-22788-008', 'SNG-22788-800', 'SNG-22788-088', |
| 29 | + 'SNG-22788-888', 'SNG-22788-808', 'SNG-22788-880', 'SNG-22788-222', 'SNG-22788-900', 'SNG-22788-202', |
| 30 | + 'SNG-22788-022', 'SNG-22788-220', 'SNG-22788-444', 'SNG-22788-400', 'SNG-22788-404', 'SNG-22788-044', |
| 31 | + 'SNG-22788-440', 'SNG-22788-333', 'SNG-22788-300', 'SNG-22788-303', 'SNG-22788-330', 'SNG-22788-033', |
| 32 | + 'SNG-22788-030', 'SNG-22788-555', 'SNG-22788-666', 'SNG-22788-600', 'SNG-22788-606', 'SNG-22788-660', |
| 33 | + 'SNG-22788-066', 'SNG-22788-060', 'SNG-22788-777', 'SNG-22788-700', 'SNG-22788-750', 'SNG-22788-850', |
| 34 | + 'SNG-22788-150', 'SNG-22788-002', 'SNG-22788-500', 'SNG-22788-000', 'SNG-22788-090', 'SNG-22788-009', |
| 35 | + 'SNG-22788-099'] |
| 36 | + for webcode in webcodes: |
| 37 | + download(webcode) |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + main() |
0 commit comments