(self)
| 381 | self.close() |
| 382 | |
| 383 | def open(self): |
| 384 | body = self.content |
| 385 | if b"<base" not in body: |
| 386 | # <head> 标签后插入一个<base href="url">标签 |
| 387 | repl = fr'\1<base href="{self.url}">' |
| 388 | body = re.sub(rb"(<head(?:>|\s.*?>))", repl.encode("utf-8"), body) |
| 389 | |
| 390 | fd, fname = tempfile.mkstemp(".html") |
| 391 | os.write(fd, body) |
| 392 | os.close(fd) |
| 393 | return webbrowser.open(f"file://{fname}") |
no test coverage detected