summaryrefslogtreecommitdiff
path: root/crocoite/behavior.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-05-12 15:37:48 +0300
committerLars-Dominik Braun <lars@6xq.net>2019-05-12 15:37:48 +0300
commitba5dbfd061d328a2140f0a7541ef0fdb6acf5903 (patch)
treed092aa0e9b401404b6463db22741511165ca1575 /crocoite/behavior.py
parent0299acfb6edf7d54ed112834a2b639567f782ab4 (diff)
downloadcrocoite-ba5dbfd061d328a2140f0a7541ef0fdb6acf5903.tar.gz
crocoite-ba5dbfd061d328a2140f0a7541ef0fdb6acf5903.tar.bz2
crocoite-ba5dbfd061d328a2140f0a7541ef0fdb6acf5903.zip
behavior: Ignore invalid URLs when extracting links
Fixes #18.
Diffstat (limited to 'crocoite/behavior.py')
-rw-r--r--crocoite/behavior.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/crocoite/behavior.py b/crocoite/behavior.py
index dca9ea0..d079603 100644
--- a/crocoite/behavior.py
+++ b/crocoite/behavior.py
@@ -328,6 +328,13 @@ class ExtractLinksEvent:
def __repr__ (self):
return f'<ExtractLinksEvent {self.links!r}>'
+def mapOrIgnore (f, l):
+ for e in l:
+ try:
+ yield f (e)
+ except:
+ pass
+
class ExtractLinks (Behavior):
"""
Extract links from a page using JavaScript
@@ -348,7 +355,7 @@ class ExtractLinks (Behavior):
tab = self.loader.tab
yield self.script
result = await tab.Runtime.evaluate (expression=str (self.script), returnByValue=True)
- yield ExtractLinksEvent (list (set (map (URL, result['result']['value']))))
+ yield ExtractLinksEvent (list (set (mapOrIgnore (URL, result['result']['value']))))
class Crash (Behavior):
""" Crash the browser. For testing only. Obviously. """