Created
November 29, 2018 15:05
-
-
Save victor-torres/98757b1cd65a5af12e0f55afe664f7cb to your computer and use it in GitHub Desktop.
[Scrapy] Remove elements from the document based on a selector or list of selectors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_selector(selector): | |
""" | |
Remove elements from the document based on a selector or list of selectors. | |
:param selector: Selector object or Selector iterable. | |
""" | |
if not hasattr(selector, '__iter__'): | |
selector = [selector] | |
for sel in selector: | |
sel.root.getparent().remove(sel.root) |
Hey @farheenfathima96,
- This pull request was merged into parsel (Scrapy dependency) so now you can run it directly from Scrapy/Parsel selectors 😃
- You're probably getting this error because you're trying to remove an element without parent or the document's root.
- If you're selecting
a.my-link::text
try usinga.my-link
instead – for example.
Hi victor-torres ,
Thank you.... It worked !!! 👍 💯
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please guide for this error 'str' object has no attribute 'root'