0

When urllib2 is used to store to disk the contents of a page like this thus:

url = 'https://huddlebuy.workable.com/jobs/194756'
response = urllib2.urlopen(url)
content = response.read()
with open('spec.html', 'w') as spec:
    print >>spec, content

When spec.thml is opened in a browser, we can see that the URLs behind links such as:

enter image description here

.. go correctly to their underling links (http://www.perkbox.co.uk/, in this case). Relative URLs though, such as /jobs/194756/candidates/new, that of the Apply button:

enter image description here

... point to a location on disk, which obviously won't exist:

file:///jobs/194756/candidates/new

Is there a known way of avoiding this, without manually reconstructing the full URL (base URL + relative URL) and then doing a find/replace in the source before saving?

2
  • No, unless you reconstruct it after you retrieve the file. Feb 9, 2016 at 19:24
  • Maybe adding a base element?
    – unor
    Feb 11, 2016 at 22:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.