Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- test_base = '''
- <head>
- <base href="http://localhost/">
- </head>
- <body>
- <a href="foo.html">foo</a>
- </body>
- '''
- test_no_base = '''
- <head>
- </head>
- <body>
- <a href="foo.html">foo</a>
- </body>
- '''
- root = html.fromstring(test_base)
- root.make_links_absolute("http://example.com/",
- resolve_base_href=False)
- # URLs should be relative to example.com url, not localhost.
- print html.tostring(root)
- print "--------------------------------------------------------------------------------"
- root = html.fromstring(test_no_base)
- root.make_links_absolute("http://example.com/",
- resolve_base_href=False)
- print html.tostring(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement