Loads an HTML string into the web browser. If new_page==True, the page will switch to: "data:text/html," If new_page==False, will load HTML into the current page.
(self, html_string, new_page=True)
| 3315 | return [e.get_attribute(attribute) for e in option_elements] |
| 3316 | |
| 3317 | def load_html_string(self, html_string, new_page=True): |
| 3318 | """Loads an HTML string into the web browser. |
| 3319 | If new_page==True, the page will switch to: "data:text/html," |
| 3320 | If new_page==False, will load HTML into the current page.""" |
| 3321 | self.wait_for_ready_state_complete() |
| 3322 | new_lines = [] |
| 3323 | lines = html_string.split("\n") |
| 3324 | for line in lines: |
| 3325 | if not line.strip().startswith("//"): |
| 3326 | new_lines.append(line) |
| 3327 | html_string = "\n".join(new_lines) |
| 3328 | soup = self.get_beautiful_soup(html_string) |
| 3329 | found_base = False |
| 3330 | links = soup.find_all("link") |
| 3331 | href = None |
| 3332 | for link in links: |
| 3333 | if link.get("rel") == ["canonical"] and link.get("href"): |
| 3334 | found_base = True |
| 3335 | href = link.get("href") |
| 3336 | href = self.get_domain_url(href) |
| 3337 | if ( |
| 3338 | found_base |
| 3339 | and html_string.count("<head>") == 1 |
| 3340 | and html_string.count("<base") == 0 |
| 3341 | ): |
| 3342 | html_string = html_string.replace( |
| 3343 | "<head>", '<head><base href="%s">' % href |
| 3344 | ) |
| 3345 | elif not found_base: |
| 3346 | bases = soup.find_all("base") |
| 3347 | for base in bases: |
| 3348 | if base.get("href"): |
| 3349 | href = base.get("href") |
| 3350 | if href: |
| 3351 | html_string = html_string.replace('base: "."', 'base: "%s"' % href) |
| 3352 | |
| 3353 | soup = self.get_beautiful_soup(html_string) |
| 3354 | scripts = soup.find_all("script") |
| 3355 | for script in scripts: |
| 3356 | if script.get("type") != "application/json": |
| 3357 | html_string = html_string.replace(str(script), "") |
| 3358 | soup = self.get_beautiful_soup(html_string) |
| 3359 | |
| 3360 | found_head = False |
| 3361 | found_body = False |
| 3362 | html_head = None |
| 3363 | html_body = None |
| 3364 | if soup.head and len(str(soup.head)) > 12: |
| 3365 | found_head = True |
| 3366 | html_head = str(soup.head) |
| 3367 | html_head = re.escape(html_head) |
| 3368 | html_head = self.__escape_quotes_if_needed(html_head) |
| 3369 | html_head = html_head.replace("\\ ", " ") |
| 3370 | if soup.body and len(str(soup.body)) > 12: |
| 3371 | found_body = True |
| 3372 | html_body = str(soup.body) |
| 3373 | html_body = html_body.replace("\xc2\xa0", " ") |
| 3374 | html_body = html_body.replace("\xc2\xa1", "¡") |