1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
|
import unittest
from w3lib.html import (
get_base_url,
get_meta_refresh,
remove_comments,
remove_tags,
remove_tags_with_content,
replace_entities,
replace_escape_chars,
replace_tags,
unquote_markup,
)
class RemoveEntitiesTest(unittest.TestCase):
def test_returns_unicode(self):
# make sure it always return uncode
assert isinstance(replace_entities(b"no entities"), str)
assert isinstance(replace_entities(b"Price: £100!"), str)
assert isinstance(replace_entities("no entities"), str)
assert isinstance(replace_entities("Price: £100!"), str)
def test_regular(self):
# regular conversions
self.assertEqual(replace_entities("As low as £100!"), "As low as \xa3100!")
self.assertEqual(
replace_entities(b"As low as £100!"), "As low as \xa3100!"
)
self.assertEqual(
replace_entities(
"redirectTo=search&searchtext=MR0221Y&aff=buyat&affsrc=d_data&cm_mmc=buyat-_-ELECTRICAL & SEASONAL-_-MR0221Y-_-9-carat gold ½oz solid crucifix pendant"
),
"redirectTo=search&searchtext=MR0221Y&aff=buyat&affsrc=d_data&cm_mmc=buyat-_-ELECTRICAL & SEASONAL-_-MR0221Y-_-9-carat gold \xbdoz solid crucifix pendant",
)
def test_keep_entities(self):
# keep some entities
self.assertEqual(
replace_entities(
b"<b>Low < High & Medium £ six</b>", keep=["lt", "amp"]
),
"<b>Low < High & Medium \xa3 six</b>",
)
self.assertEqual(
replace_entities(
"<b>Low < High & Medium £ six</b>", keep=["lt", "amp"]
),
"<b>Low < High & Medium \xa3 six</b>",
)
def test_illegal_entities(self):
self.assertEqual(
replace_entities(
"a < b &illegal; c � six", remove_illegal=False
),
"a < b &illegal; c � six",
)
self.assertEqual(
replace_entities(
"a < b &illegal; c � six", remove_illegal=True
),
"a < b c six",
)
self.assertEqual(replace_entities("x≤y"), "x\u2264y")
self.assertEqual(replace_entities("xy"), "xy")
self.assertEqual(replace_entities("xy", remove_illegal=False), "xy")
self.assertEqual(replace_entities("�"), "")
self.assertEqual(
replace_entities("�", remove_illegal=False), "�"
)
def test_browser_hack(self):
# check browser hack for numeric character references in the 80-9F range
self.assertEqual(replace_entities("x™y", encoding="cp1252"), "x\u2122y")
self.assertEqual(replace_entities("x™y", encoding="cp1252"), "x\u2122y")
def test_missing_semicolon(self):
for entity, result in (
("<<!", "<<!"),
("<!", "<!"),
("A ", "A "),
("A!", "A!"),
("Ah", "Ah"),
("A!", "A!"),
("Ax", "Ax"),
("³!", "\u00B3!"),
("Á!", "\u00C1!"),
("☃!", "\u2603!"),
("™", "\u2122"),
("™", "\u2122"),
):
self.assertEqual(replace_entities(entity, encoding="cp1252"), result)
self.assertEqual(
replace_entities(f"x{entity}y", encoding="cp1252"), f"x{result}y"
)
def test_encoding(self):
self.assertEqual(
replace_entities(b"x\x99™™y", encoding="cp1252"),
"x\u2122\u2122\u2122y",
)
class ReplaceTagsTest(unittest.TestCase):
def test_returns_unicode(self):
# make sure it always return uncode
assert isinstance(replace_tags(b"no entities"), str)
assert isinstance(replace_tags("no entities"), str)
def test_replace_tags(self):
self.assertEqual(
replace_tags("This text contains <a>some tag</a>"),
"This text contains some tag",
)
self.assertEqual(
replace_tags(b"This text is very im<b>port</b>ant", " "),
"This text is very im port ant",
)
def test_replace_tags_multiline(self):
self.assertEqual(
replace_tags(b'Click <a class="one"\r\n href="url">here</a>'), "Click here"
)
class RemoveCommentsTest(unittest.TestCase):
def test_returns_unicode(self):
# make sure it always return unicode
assert isinstance(remove_comments(b"without comments"), str)
assert isinstance(remove_comments(b"<!-- with comments -->"), str)
assert isinstance(remove_comments("without comments"), str)
assert isinstance(remove_comments("<!-- with comments -->"), str)
def test_no_comments(self):
# text without comments
self.assertEqual(
remove_comments("text without comments"), "text without comments"
)
def test_remove_comments(self):
# text with comments
self.assertEqual(remove_comments("<!--text with comments-->"), "")
self.assertEqual(remove_comments("Hello<!--World-->"), "Hello")
self.assertEqual(remove_comments("Hello<!--My\nWorld-->"), "Hello")
self.assertEqual(
remove_comments(b"test <!--textcoment--> whatever"), "test whatever"
)
self.assertEqual(
remove_comments(b"test <!--\ntextcoment\n--> whatever"), "test whatever"
)
self.assertEqual(remove_comments(b"test <!--"), "test ")
class RemoveTagsTest(unittest.TestCase):
def test_returns_unicode(self):
# make sure it always return unicode
assert isinstance(remove_tags(b"no tags"), str)
assert isinstance(remove_tags(b"no tags", which_ones=("p",)), str)
assert isinstance(remove_tags(b"<p>one tag</p>"), str)
assert isinstance(remove_tags(b"<p>one tag</p>", which_ones=("p",)), str)
assert isinstance(remove_tags(b"<a>link</a>", which_ones=("b",)), str)
assert isinstance(remove_tags("no tags"), str)
assert isinstance(remove_tags("no tags", which_ones=("p",)), str)
assert isinstance(remove_tags("<p>one tag</p>"), str)
assert isinstance(remove_tags("<p>one tag</p>", which_ones=("p",)), str)
assert isinstance(remove_tags("<a>link</a>", which_ones=("b",)), str)
def test_remove_tags_without_tags(self):
# text without tags
self.assertEqual(remove_tags("no tags"), "no tags")
self.assertEqual(remove_tags("no tags", which_ones=("p", "b")), "no tags")
def test_remove_tags(self):
# text with tags
self.assertEqual(remove_tags("<p>one p tag</p>"), "one p tag")
self.assertEqual(
remove_tags("<p>one p tag</p>", which_ones=("b",)), "<p>one p tag</p>"
)
self.assertEqual(
remove_tags(
"<b>not will removed</b><i>i will removed</i>", which_ones=("i",)
),
"<b>not will removed</b>i will removed",
)
def test_remove_tags_with_attributes(self):
# text with tags and attributes
self.assertEqual(
remove_tags('<p align="center" class="one">texty</p>'), "texty"
)
self.assertEqual(
remove_tags('<p align="center" class="one">texty</p>', which_ones=("b",)),
'<p align="center" class="one">texty</p>',
)
def test_remove_empty_tags(self):
# text with empty tags
self.assertEqual(remove_tags("a<br />b<br/>c"), "abc")
self.assertEqual(remove_tags("a<br />b<br/>c", which_ones=("br",)), "abc")
def test_keep_argument(self):
self.assertEqual(
remove_tags("<p>a<br />b<br/>c</p>", keep=("br",)), "a<br />b<br/>c"
)
self.assertEqual(
remove_tags("<p>a<br />b<br/>c</p>", keep=("p",)), "<p>abc</p>"
)
self.assertEqual(
remove_tags("<p>a<br />b<br/>c</p>", keep=("p", "br", "div")),
"<p>a<br />b<br/>c</p>",
)
def test_uppercase_tags(self):
self.assertEqual(
remove_tags(
"<foo></foo><bar></bar><baz/>", which_ones=("Foo", "BAR", "baZ")
),
"",
)
self.assertEqual(
remove_tags(
"<FOO></foO><BaR></bAr><BAZ/>", which_ones=("foo", "bar", "baz")
),
"",
)
class RemoveTagsWithContentTest(unittest.TestCase):
def test_returns_unicode(self):
# make sure it always return unicode
assert isinstance(remove_tags_with_content(b"no tags"), str)
assert isinstance(remove_tags_with_content(b"no tags", which_ones=("p",)), str)
assert isinstance(
remove_tags_with_content(b"<p>one tag</p>", which_ones=("p",)), str
)
assert isinstance(
remove_tags_with_content(b"<a>link</a>", which_ones=("b",)), str
)
assert isinstance(remove_tags_with_content("no tags"), str)
assert isinstance(remove_tags_with_content("no tags", which_ones=("p",)), str)
assert isinstance(
remove_tags_with_content("<p>one tag</p>", which_ones=("p",)), str
)
assert isinstance(
remove_tags_with_content("<a>link</a>", which_ones=("b",)), str
)
def test_without_tags(self):
# text without tags
self.assertEqual(remove_tags_with_content("no tags"), "no tags")
self.assertEqual(
remove_tags_with_content("no tags", which_ones=("p", "b")), "no tags"
)
def test_with_tags(self):
# text with tags
self.assertEqual(
remove_tags_with_content("<p>one p tag</p>"), "<p>one p tag</p>"
)
self.assertEqual(
remove_tags_with_content("<p>one p tag</p>", which_ones=("p",)), ""
)
self.assertEqual(
remove_tags_with_content(
"<b>not will removed</b><i>i will removed</i>", which_ones=("i",)
),
"<b>not will removed</b>",
)
def test_empty_tags(self):
# text with empty tags
self.assertEqual(
remove_tags_with_content("<br/>a<br />", which_ones=("br",)), "a"
)
def test_tags_with_shared_prefix(self):
# https://github.com/scrapy/w3lib/issues/114
self.assertEqual(
remove_tags_with_content("<span></span><s></s>", which_ones=("s",)),
"<span></span>",
)
class ReplaceEscapeCharsTest(unittest.TestCase):
def test_returns_unicode(self):
# make sure it always return unicode
assert isinstance(replace_escape_chars(b"no ec"), str)
assert isinstance(replace_escape_chars(b"no ec", replace_by="str"), str)
assert isinstance(replace_escape_chars(b"no ec", replace_by="str"), str)
assert isinstance(replace_escape_chars(b"no ec", which_ones=("\n", "\t")), str)
assert isinstance(replace_escape_chars("no ec"), str)
assert isinstance(replace_escape_chars("no ec", replace_by="str"), str)
assert isinstance(replace_escape_chars("no ec", which_ones=("\n", "\t")), str)
def test_without_escape_chars(self):
# text without escape chars
self.assertEqual(replace_escape_chars("no ec"), "no ec")
self.assertEqual(replace_escape_chars("no ec", which_ones=("\n",)), "no ec")
def test_with_escape_chars(self):
# text with escape chars
self.assertEqual(replace_escape_chars("escape\n\n"), "escape")
self.assertEqual(
replace_escape_chars("escape\n", which_ones=("\t",)), "escape\n"
)
self.assertEqual(
replace_escape_chars("escape\tchars\n", which_ones=("\t",)), "escapechars\n"
)
self.assertEqual(
replace_escape_chars("escape\tchars\n", replace_by=" "), "escape chars "
)
self.assertEqual(
replace_escape_chars("escape\tchars\n", replace_by="\xa3"),
"escape\xa3chars\xa3",
)
self.assertEqual(
replace_escape_chars("escape\tchars\n", replace_by=b"\xc2\xa3"),
"escape\xa3chars\xa3",
)
class UnquoteMarkupTest(unittest.TestCase):
sample_txt1 = """<node1>hi, this is sample text with entities: & ©
<![CDATA[although this is inside a cdata! & "]]></node1>"""
sample_txt2 = (
"<node2>blah&blah<![CDATA[blahblahblah!£]]>moreblah<></node2>"
)
sample_txt3 = "something£&more<node3><![CDATA[things, stuff, and such]]>what"ever</node3><node4"
def test_returns_unicode(self):
# make sure it always return unicode
assert isinstance(unquote_markup(self.sample_txt1.encode("latin-1")), str)
assert isinstance(unquote_markup(self.sample_txt2), str)
def test_unquote_markup(self):
self.assertEqual(
unquote_markup(self.sample_txt1),
"""<node1>hi, this is sample text with entities: & \xa9
although this is inside a cdata! & "</node1>""",
)
self.assertEqual(
unquote_markup(self.sample_txt2),
"<node2>blah&blahblahblahblah!£moreblah<></node2>",
)
self.assertEqual(
unquote_markup(self.sample_txt1 + self.sample_txt2),
"""<node1>hi, this is sample text with entities: & \xa9
although this is inside a cdata! & "</node1><node2>blah&blahblahblahblah!£moreblah<></node2>""",
)
self.assertEqual(
unquote_markup(self.sample_txt3),
'something\xa3&more<node3>things, stuff, and suchwhat"ever</node3><node4',
)
class GetBaseUrlTest(unittest.TestCase):
def test_get_base_url(self):
baseurl = "https://example.org"
text = """\
<html>\
<head><title>Dummy</title><base href='http://example.org/something' /></head>\
<body>blahablsdfsal&</body>\
</html>"""
self.assertEqual(get_base_url(text, baseurl), "http://example.org/something")
self.assertEqual(
get_base_url(text, baseurl.encode("ascii")), "http://example.org/something"
)
def test_base_url_in_comment(self):
self.assertEqual(
get_base_url("""<!-- <base href="http://example.com/"/> -->"""), ""
)
self.assertEqual(
get_base_url("""<!-- <base href="http://example.com/"/>"""), ""
)
self.assertEqual(
get_base_url("""<!-- <base href="http://example.com/"/> --"""), ""
)
self.assertEqual(
get_base_url(
"""<!-- <!-- <base href="http://example.com/"/> -- --> <base href="http://example_2.com/"/> """
),
"http://example_2.com/",
)
self.assertEqual(
get_base_url(
"""<!-- <base href="http://example.com/"/> --> <!-- <base href="http://example_2.com/"/> --> <base href="http://example_3.com/"/>"""
),
"http://example_3.com/",
)
def test_relative_url_with_absolute_path(self):
baseurl = "https://example.org"
text = """\
<html>\
<head><title>Dummy</title><base href='/absolutepath' /></head>\
<body>blahablsdfsal&</body>\
</html>"""
self.assertEqual(
get_base_url(text, baseurl), "https://example.org/absolutepath"
)
def test_no_scheme_url(self):
baseurl = "https://example.org"
text = b"""\
<html>\
<head><title>Dummy</title><base href='//noscheme.com/path' /></head>\
<body>blahablsdfsal&</body>\
</html>"""
self.assertEqual(get_base_url(text, baseurl), "https://noscheme.com/path")
def test_attributes_before_href(self):
baseurl = "https://example.org"
text = """\
<html>\
<head><title>Dummy</title><base id='my_base_tag' href='http://example.org/something' /></head>\
<body>blahablsdfsal&</body>\
</html>"""
self.assertEqual(get_base_url(text, baseurl), "http://example.org/something")
def test_tag_name(self):
baseurl = "https://example.org"
text = """\
<html>\
<head><title>Dummy</title><basefoo href='http://example.org/something' /></head>\
<body>blahablsdfsal&</body>\
</html>"""
self.assertEqual(get_base_url(text, baseurl), "https://example.org")
def test_get_base_url_utf8(self):
baseurl = "https://example.org"
text = """
<html>
<head><title>Dummy</title><base href='http://example.org/snowman\u2368' /></head>
<body>blahablsdfsal&</body>
</html>"""
self.assertEqual(
get_base_url(text, baseurl), "http://example.org/snowman%E2%8D%A8"
)
def test_get_base_url_latin1(self):
# page encoding does not affect URL path encoding before percent-escaping
# we should still use UTF-8 by default
baseurl = "https://example.org"
text = """
<html>
<head><title>Dummy</title><base href='http://example.org/sterling\u00a3' /></head>
<body>blahablsdfsal&</body>
</html>"""
self.assertEqual(
get_base_url(text, baseurl, encoding="latin-1"),
"http://example.org/sterling%C2%A3",
)
def test_get_base_url_latin1_percent(self):
# non-UTF-8 percent-encoded characters sequence are left untouched
baseurl = "https://example.org"
text = """
<html>
<head><title>Dummy</title><base href='http://example.org/sterling%a3' /></head>
<body>blahablsdfsal&</body>
</html>"""
self.assertEqual(get_base_url(text, baseurl), "http://example.org/sterling%a3")
class GetMetaRefreshTest(unittest.TestCase):
def test_get_meta_refresh(self):
baseurl = "http://example.org"
body = """
<html>
<head><title>Dummy</title><meta http-equiv="refresh" content="5;url=http://example.org/newpage" /></head>
<body>blahablsdfsal&</body>
</html>"""
self.assertEqual(
get_meta_refresh(body, baseurl), (5, "http://example.org/newpage")
)
def test_without_url(self):
# refresh without url should return (None, None)
baseurl = "http://example.org"
body = """<meta http-equiv="refresh" content="5" />"""
self.assertEqual(get_meta_refresh(body, baseurl), (None, None))
body = """<meta http-equiv="refresh" content="5;
url=http://example.org/newpage" /></head>"""
self.assertEqual(
get_meta_refresh(body, baseurl), (5, "http://example.org/newpage")
)
def test_multiline(self):
# meta refresh in multiple lines
baseurl = "http://example.org"
body = """<html><head>
<META
HTTP-EQUIV="Refresh"
CONTENT="1; URL=http://example.org/newpage">"""
self.assertEqual(
get_meta_refresh(body, baseurl), (1, "http://example.org/newpage")
)
def test_entities_in_redirect_url(self):
# entities in the redirect url
baseurl = "http://example.org"
body = """<meta http-equiv="refresh" content="3; url='http://www.example.com/other'">"""
self.assertEqual(
get_meta_refresh(body, baseurl), (3, "http://www.example.com/other")
)
def test_relative_redirects(self):
# relative redirects
baseurl = "http://example.com/page/this.html"
body = """<meta http-equiv="refresh" content="3; url=other.html">"""
self.assertEqual(
get_meta_refresh(body, baseurl), (3, "http://example.com/page/other.html")
)
def test_nonascii_url_utf8(self):
# non-ascii chars in the url (utf8 - default)
baseurl = "http://example.com"
body = b"""<meta http-equiv="refresh" content="3; url=http://example.com/to\xc2\xa3">"""
self.assertEqual(
get_meta_refresh(body, baseurl), (3, "http://example.com/to%C2%A3")
)
def test_nonascii_url_latin1(self):
# non-ascii chars in the url path (latin1)
# should end up UTF-8 encoded anyway
baseurl = "http://example.com"
body = b"""<meta http-equiv="refresh" content="3; url=http://example.com/to\xa3">"""
self.assertEqual(
get_meta_refresh(body, baseurl, "latin1"),
(3, "http://example.com/to%C2%A3"),
)
def test_nonascii_url_latin1_query(self):
# non-ascii chars in the url path and query (latin1)
# only query part should be kept latin1 encoded before percent escaping
baseurl = "http://example.com"
body = b"""<meta http-equiv="refresh" content="3; url=http://example.com/to\xa3?unit=\xb5">"""
self.assertEqual(
get_meta_refresh(body, baseurl, "latin1"),
(3, "http://example.com/to%C2%A3?unit=%B5"),
)
def test_commented_meta_refresh(self):
# html commented meta refresh header must not directed
baseurl = "http://example.com"
body = """<!--<meta http-equiv="refresh" content="3; url=http://example.com/">-->"""
self.assertEqual(get_meta_refresh(body, baseurl), (None, None))
def test_html_comments_with_uncommented_meta_refresh(self):
# html comments must not interfere with uncommented meta refresh header
baseurl = "http://example.com"
body = """<!-- commented --><meta http-equiv="refresh" content="3; url=http://example.com/">-->"""
self.assertEqual(get_meta_refresh(body, baseurl), (3, "http://example.com/"))
def test_float_refresh_intervals(self):
# float refresh intervals
baseurl = "http://example.com"
body = """<meta http-equiv="refresh" content=".1;URL=index.html" />"""
self.assertEqual(
get_meta_refresh(body, baseurl), (0.1, "http://example.com/index.html")
)
body = """<meta http-equiv="refresh" content="3.1;URL=index.html" />"""
self.assertEqual(
get_meta_refresh(body, baseurl), (3.1, "http://example.com/index.html")
)
def test_tag_name(self):
baseurl = "http://example.org"
body = """
<html>
<head><title>Dummy</title><metafoo http-equiv="refresh" content="5;url=http://example.org/newpage" /></head>
<body>blahablsdfsal&</body>
</html>"""
self.assertEqual(get_meta_refresh(body, baseurl), (None, None))
def test_leading_newline_in_url(self):
baseurl = "http://example.org"
body = """
<html>
<head><title>Dummy</title><meta http-equiv="refresh" content="0; URL=
http://www.example.org/index.php" />
</head>
</html>"""
self.assertEqual(
get_meta_refresh(body, baseurl), (0.0, "http://www.example.org/index.php")
)
def test_inside_noscript(self):
baseurl = "http://example.org"
body = """
<html>
<head><noscript><meta http-equiv="refresh" content="0;url=http://example.org/javascript_required" /></noscript></head>
</html>"""
self.assertEqual(get_meta_refresh(body, baseurl), (None, None))
self.assertEqual(
get_meta_refresh(body, baseurl, ignore_tags=()),
(0.0, "http://example.org/javascript_required"),
)
def test_inside_script(self):
baseurl = "http://example.org"
body = """
<html>
<head><script>if(!foobar()){ $('<meta http-equiv="refresh" content="0;url=http://example.org/foobar_required" />').appendTo('body'); }</script></head>
</html>"""
self.assertEqual(get_meta_refresh(body, baseurl), (None, None))
self.assertEqual(
get_meta_refresh(body, baseurl, ignore_tags=()),
(0.0, "http://example.org/foobar_required"),
)
def test_redirections_in_different_ordering__in_meta_tag(self):
baseurl = "http://localhost:8000"
url1 = '<html><head><meta http-equiv="refresh" content="0;url=dummy.html"></head></html>'
url2 = '<html><head><meta content="0;url=dummy.html" http-equiv="refresh"></head></html>'
self.assertEqual(
get_meta_refresh(url1, baseurl), (0.0, "http://localhost:8000/dummy.html")
)
self.assertEqual(
get_meta_refresh(url2, baseurl), (0.0, "http://localhost:8000/dummy.html")
)
|