diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2019-05-12 15:37:48 +0300 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2019-05-12 15:37:48 +0300 |
commit | ba5dbfd061d328a2140f0a7541ef0fdb6acf5903 (patch) | |
tree | d092aa0e9b401404b6463db22741511165ca1575 /crocoite/behavior.py | |
parent | 0299acfb6edf7d54ed112834a2b639567f782ab4 (diff) | |
download | crocoite-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.py | 9 |
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. """ |