return empty text when get each attr #2352
MahmoudHooda2019
started this conversation in
Ideas
Replies: 2 comments
-
it the same thing for get each text .....etc |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, Yes, right,
Similarly for If you want to get a value for each Element, even if a given Element doesn't have that value, you can do something like: List<String> attrs = elements.stream()
.map(el -> el.hasAttr("yourAttr") ? el.attr("yourAttr") : "")
.collect(Collectors.toList()); Or, make a helper like: public static List<String> eachAttrOr(Elements elements, String attr, String fallback) {
return elements.stream()
.map(el -> el.hasAttr(attr) ? el.attr(attr) : fallback)
.collect(Collectors.toList());
} I am not sure it make sense to add a bunch of one-liner helpers to Elements though, I tend to think that's better in user code. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hi it is just small thing when i am using get each attr for Elements, when one of the element in elements not have the attrKey he is not put empty text instade of that he is skip it, use can create same function but with parmater like ifNotExist or something like that, thank you for awsome library ❤
Beta Was this translation helpful? Give feedback.
All reactions