i have written python script make call server , fetch response. while making call server, pass few values in body of request. value supposed fetched reading text file. text file sample given below.
my text file sample:
host: localhost:8080 connection: keep-alive ..... ..... {"token":"abcdefhutryskslkslksslslks=="}post /fill/entry/login http/1.1 host: localhost:8080 connection: keep-alive ..... ..... {"value":"abcdefghijklmnopqrstuvwxyz", "pass":"123456789zxcvbnmljhgfds", "token":"abcdefghijklmnopqrstuvwxyz=="}post /fill/health http/1.1
here, if can observe, different responses. need capture string starts {"value" , ends "} (the second part of response seen in sample).
on searching in stack overflow, came across scenarios extract string have definite start point , definite end point. in case, though start point can identified uniquely using search string " {"url ", end point cannot identified text file contains multiple other parentheses well.
any suggestions/pointers on fetching specific part of sting text file(as stated above) helpful.
a re
example interpreter:
>>> open('file') f: ... raw = f.read() >>> >>> import re >>> pat = re.compile(r'{"value":[^{]+}') >>> pat.findall(raw) ['{"value":"abcdefghijklmnopqrstuvwxyz",\n "pass":"123456789zxcvbnmljhgfds",\n "token":"abcdefghijklmnopqrstuvwxyz=="}'] >>> pat.search(raw).group() '{"value":"abcdefghijklmnopqrstuvwxyz",\n "pass":"123456789zxcvbnmljhgfds",\n "token":"abcdefghijklmnopqrstuvwxyz=="}'
Comments
Post a Comment