Since there is not anything else that was more intricate, I wanted to share this as it helped me out.
This is what I originally used:
import requests
import re
url = 'https://stackoverflow.com/questions/10711116/strip-spaces-tabs-newlines-python' # noqa
headers = {'user-agent': 'my-app/0.0.1'}
r = requests.get(url, headers=headers)
print("{}".format(r.content))
Undesired Result:
b'<!DOCTYPE html>\r\n\r\n\r\n <html itemscope itemtype="http://schema.org/QAPage" class="html__responsive">\r\n\r\n <head>\r\n\r\n <title>string - Strip spaces/tabs/newlines - python - Stack Overflow</title>\r\n <link
This is what I changed it to:
import requests
import re
url = 'https://stackoverflow.com/questions/10711116/strip-spaces-tabs-newlines-python' # noqa
headers = {'user-agent': 'my-app/0.0.1'}
r = requests.get(url, headers=headers)
regex = r'\s+'
print("CNT: {}".format(re.sub(regex, " ", r.content.decode('utf-8'))))
Desired Result:
<!DOCTYPE html> <html itemscope itemtype="http://schema.org/QAPage" class="html__responsive"> <head> <title>string - Strip spaces/tabs/newlines - python - Stack Overflow</title>
The precise regex that @MattH had mentioned, was what worked for me in fitting it into my code. Thanks!
Note: This is python3