Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. import requests, lxml.html
  2.  
  3. s = requests.session()
  4. login = s.get('http://localhost:8090/index.php')
  5. login_html = lxml.html.fromstring(login.text)
  6. hidden_inputs = login_html.xpath(r'//form//input[@type="hidden"]')
  7. form = {x.attrib["name"]: x.attrib["value"] for x in hidden_inputs}
  8.  
  9.  
  10. #print (s.cookies)
  11. #print(form)
  12.  
  13. form['login_name'] = 'glpi'
  14. form['login_password'] = 'glpi'
  15.  
  16. headers = {
  17.     'Host': 'localhost:8090',
  18.     'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0',
  19.     'Accept': '*/*',
  20.     'Accept-Language': 'en-US,en;q=0.5',
  21.     'X-Requested-With': 'XMLHttpRequest',
  22.     'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  23.     'Referer': 'http://localhost:8090/login.php',
  24.     'DNT': '1',
  25.     'Connection': 'keep-alive',
  26.     'Pragma': 'no-cache',
  27.     'Cache-Control': 'no-cache',
  28. }
  29.  
  30. response = s.post('http://localhost:8090/front/central.php', headers=headers, data=form)
  31.  
  32. headers = {
  33.     'Host': 'localhost:8090',
  34.     'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0',
  35.     'Accept': '*/*',
  36.     'Accept-Language': 'en-US,en;q=0.5',
  37.     'X-Requested-With': 'XMLHttpRequest',
  38.     'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  39.     'Referer': 'http://localhost:8090/front/ticket.form.php?id=1',
  40.     'DNT': '1',
  41.     'Connection': 'keep-alive',
  42.     'Pragma': 'no-cache',
  43.     'Cache-Control': 'no-cache',
  44. }
  45.  
  46. data = [
  47.   ('target', '/front/ticket.form.php'),
  48.   ('itemtype', 'Ticket'),
  49.   ('glpi_tab', 'TicketTask$1'),
  50.   ('id', '1'),
  51.   ('template_preview', '0'),
  52. ]
  53.  
  54. response = requests.post('http://localhost:8090/ajax/common.tabs.php', headers=headers, data=data)
  55. # O usando la cookie mas explicita:
  56. #
  57. #   response = requests.post('http://localhost:8090/ajax/common.tabs.php', headers=headers, coockies=cookies, data=data)
  58. #
  59. # Si en el request envio las cookies como
  60. #   cookies = {
  61. #    'PHPSESSID':  s.cookies['PHPSESSID'],
  62. #   }
  63. #
  64. #  Tampoco funciona.
  65.  
  66. print (response.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement