-1

so I have the data from a HTTP GET request in the following way:

GET http://google.com/ HTTP/1.1
Host: google.com
Proxy-Connection: keep-alive
Cache-Control: max-age=0
etc etc

I would like extract the url next to GET and store it in a variable..looked through some stuff on the net but can't find a solid way of doing it. Anyone got any suggestions?

Hassan Ali
  • 149
  • 1
  • 4
  • 11
  • 1
    (1) That’s not a valid HTTP request; (2) Have you tried basic string manipulation? – poke Feb 22 '16 at 13:58

1 Answers1

0

Using regexp :

import re

url_pattern = re.compile("^GET (.*)[ ].*")
line = "GET http://google.com/ HTTP/1.1"
url = url_pattern.match(line).group(1)

If you are sure there is never a space in URL :-D

Benjamin
  • 3,350
  • 4
  • 24
  • 49