I\'m trying to search a webpage using regular expressions, but I\'m getting the following error:
TypeError: can\'t use a string pattern on a bytes-lik
Here is an example simple http request (that I tested and works)...
address = "http://stackoverflow.com"
urllib.request.urlopen(address).read().decode('utf-8')
Make sure to read the documentation.
https://docs.python.org/3/library/urllib.request.html
If you want to do something more detailed GET/POST REQUEST.
import urllib.request
# HTTP REQUEST of some address
def REQUEST(address):
req = urllib.request.Request(address)
req.add_header('User-Agent', 'NAME (Linux/MacOS; FROM, USA)')
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8') # make sure its all text not binary
print("REQUEST (ONLINE): " + address)
return html