Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def simple_get(url):
- """
- Attempts to get the content at `url` by making an HTTP GET request.
- If the content-type of response is some kind of HTML/XML, return the
- text content, otherwise return None.
- """
- try:
- resp = requests.get(url)
- ctype = resp.headers['Content-Type'].lower()
- if (resp.status_code == 200 and ctype is not None and 'html' in ctype):
- # well-formed response
- return resp.content
- except RequestException as e:
- print(f'Error during requests to {url} : {e}')
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement