fix soup head being None

If the HTML response returns without a head
(e.g. because a permanent redirect)

then soup.head will be None and the page will crash.

We append the script tag only of soup finds a page head.

Signed-off-by: Alex D <ddalex@gmail.com>