I am trying to search inside the response of a request (I used Requests and Python). I get the response and check the type of it, which is UNICODE.
I want to retrieve a specific link which is located between two other strings. I have tried different ways found online such as the:
result = re.**search**('Currently: <a ', s)url_file = response.**find**('Currently: <a ', beg=0, end=len(response))Also tried to transform the UNICODE string to a normal string:
s = unicodedata.normalize(response, title).encode('ascii','ignore')I get an error.
EDITED
For example:
This works:
s = 'asdf=5;iwantthis123jasd'
result = re.search('asdf=5;(.*)123jasd', s)
print result.group(1)
This doesn't work (returns error):
s = 'Currently: <a '
result = re.search(r.text, s)
print result.group(1)
You can access the raw text from the response object with the text attribute.
res = requests.get("http://google.com")
re.search('pattern', res.text)
Then, just use a regular expression to "search" or "match" the entire response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With