Advertisement
Guest User

Untitled

a guest
Jan 30th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. from lxml import html
  2.  
  3. test_base = '''
  4. <head>
  5. <base href="http://localhost/">
  6. </head>
  7. <body>
  8. <a href="foo.html">foo</a>
  9. </body>
  10. '''
  11.  
  12. test_no_base = '''
  13. <head>
  14. </head>
  15. <body>
  16. <a href="foo.html">foo</a>
  17. </body>
  18. '''
  19.  
  20. root = html.fromstring(test_base)
  21. root.make_links_absolute("http://example.com/",
  22.                          resolve_base_href=False)
  23. # URLs should be relative to example.com url, not localhost.
  24. print html.tostring(root)
  25.  
  26. print "--------------------------------------------------------------------------------"
  27.  
  28. root = html.fromstring(test_no_base)
  29. root.make_links_absolute("http://example.com/",
  30.                          resolve_base_href=False)
  31. print html.tostring(root)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement