Convenience function, which returns all links (a,link,img,script,meta). :param absolute: Try to build all the links in absolute form instead of "as is", often relative. :return: List of URLs.
(self, absolute=True)
| 1302 | return [element.create(asset, self) for asset in all_assets] |
| 1303 | |
| 1304 | async def get_all_urls(self, absolute=True) -> List[str]: |
| 1305 | """ |
| 1306 | Convenience function, which returns all links (a,link,img,script,meta). |
| 1307 | :param absolute: |
| 1308 | Try to build all the links in absolute form |
| 1309 | instead of "as is", often relative. |
| 1310 | :return: List of URLs. |
| 1311 | """ |
| 1312 | import urllib.parse |
| 1313 | |
| 1314 | res = [] |
| 1315 | all_assets = await self.query_selector_all( |
| 1316 | selector="a,link,img,script,meta" |
| 1317 | ) |
| 1318 | for asset in all_assets: |
| 1319 | if not absolute: |
| 1320 | res.append(asset.src or asset.href) |
| 1321 | else: |
| 1322 | for k, v in asset.attrs.items(): |
| 1323 | if k in ("src", "href"): |
| 1324 | if "#" in v: |
| 1325 | continue |
| 1326 | if not any([_ in v for _ in ("http", "//", "/")]): |
| 1327 | continue |
| 1328 | abs_url = urllib.parse.urljoin( |
| 1329 | "/".join(self.url.rsplit("/")[:3]), v |
| 1330 | ) |
| 1331 | if not abs_url.startswith(("http", "//", "ws")): |
| 1332 | continue |
| 1333 | res.append(abs_url) |
| 1334 | return res |
| 1335 | |
| 1336 | async def get_html(self): |
| 1337 | element = await self.find("html", timeout=1) |
nothing calls this directly
no test coverage detected