MonaChanDev

Untitled

Dec 6th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. url = "https://vecchiochan.com/t/res/1533.html"
  4. # ottengo la risposta dal server
  5. h_response = requests.get(url)
  6. # ne prelevo il  file HTML
  7. data = h_response.text
  8. # analizzo l'HTML
  9. soup = BeautifulSoup(h_response._content.decode('utf-8'), 'html.parser')
  10. # array di dizionari contenenti nome-valore
  11. arr:dict = {}
  12. # ottengo tutti il form che mi consente di postare
  13. form = soup.find("form", attrs={"name": "post"})
  14. # trovo tutti gli input interni al form  compresi quelli nascosti
  15. inputs = form.find_all("input")
  16. # per ogni elemento input
  17. for e in inputs:
  18.     # inizializzo il valore vuoto
  19.     value = ""
  20.     # se l'elelemnto ha l'attributo value
  21.     if e.has_attr("value"):
  22.         # imposto il valore
  23.         value = e["value"]
  24.         if e["name"] == "password":
  25.             value = "ricchione"
  26.         # creo un dizionario nome-valore
  27.         dictx = {str(e["name"]).encode('utf-8') : (None, str(value).encode('utf-8'))}
  28.         # lo salvo nell'array
  29.         arr.update(dictx)
  30. # trovo anche tutte le textarea interne al form
  31. ta = form.find_all("textarea")
  32. # per ogni textarea trovata
  33. for tas in ta:
  34.     # salvo il nome della textarea e il suo contenuto
  35.     if tas["name"] == "body":
  36.         # qui inserisco il corpo del post
  37.        arr.update({str(tas["name"]).encode('utf-8'): (None, "Ciao da Python".encode('utf-8'))})
  38.     else:
  39.         arr.update({str(tas["name"]).encode('utf-8'): (None, str((tas.text)).encode('utf-8'))})
  40. # aggiungo chiave mancante
  41. arr.update({"json_response".encode('utf-8'):(None, "1".encode('utf-8'))})
  42. #inoltro la richiesta
  43. response = requests.post("https://vecchiochan.com/post.php", files=arr, stream=True)
  44.  
  45. print("\nHeader risposta")
  46. print(response.headers)
  47. print("\n\n\n")
  48. # view content
  49. aa = ""
  50. for chunk in response.iter_content(chunk_size=1024):
  51.     if chunk:
  52.         print(chunk)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment