Advertisement
albin900

Untitled

Aug 22nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import requests, urllib
  2.  
  3. ### Getting contents from a site very simple
  4.  
  5. result = requests.get( "https://icanhazip.com" )
  6.  
  7. print result.text
  8.  
  9. ### Getting contents from a site with headers
  10.  
  11. # Easier to read the code when it's formatted
  12.  
  13. result = requests.get(
  14. "https://icanhazip.com",
  15. headers={
  16. "Some-Header-Here": "Some-Value-Here",
  17. "User-Agent": "Requests/Python"
  18. }
  19. )
  20.  
  21. ### POSTING data used when submitting a form like logging in/signup etc
  22.  
  23. result = requests.post(
  24. "https://sitetologin.com/login",
  25. headers={
  26. "User-Agent": "User-agent (important)"
  27. },
  28. data=urllib.urlencode({
  29. "username": "username123",
  30. "password": "password123"
  31. })
  32. )
  33.  
  34. if result.text == "success":
  35. print "we logged in fine!"
  36. else:
  37. print "No! site didn't return success"
  38.  
  39.  
  40. #### Proxies
  41.  
  42. result = requests.get(
  43. "https://icanhazip.com",
  44. proxies={
  45. "https": "https://PROXY:PORT"
  46. }
  47. )
  48.  
  49. print result.text #should respond with the proxies ip
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement