mirror of https://github.com/scrapy/scrapy.git
Merge pull request #1205 from Curita/htmlparser-deprecation
[MRG+1] Deprecate htmlparser link extractor
This commit is contained in:
commit
9576fb5744
|
|
@ -2,6 +2,7 @@
|
|||
HTMLParser-based link extractor
|
||||
"""
|
||||
|
||||
import warnings
|
||||
from HTMLParser import HTMLParser
|
||||
from six.moves.urllib.parse import urljoin
|
||||
|
||||
|
|
@ -9,12 +10,20 @@ from w3lib.url import safe_url_string
|
|||
|
||||
from scrapy.link import Link
|
||||
from scrapy.utils.python import unique as unique_list
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
|
||||
|
||||
class HtmlParserLinkExtractor(HTMLParser):
|
||||
|
||||
def __init__(self, tag="a", attr="href", process=None, unique=False):
|
||||
HTMLParser.__init__(self)
|
||||
|
||||
warnings.warn(
|
||||
"HtmlParserLinkExtractor is deprecated and will be removed in "
|
||||
"future releases. Please use scrapy.linkextractors.LinkExtractor",
|
||||
ScrapyDeprecationWarning, stacklevel=2,
|
||||
)
|
||||
|
||||
self.scan_tag = tag if callable(tag) else lambda t: t == tag
|
||||
self.scan_attr = attr if callable(attr) else lambda a: a == attr
|
||||
self.process_attr = process if callable(process) else lambda v: v
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class BaseSgmlLinkExtractor(SGMLParser):
|
|||
warnings.warn(
|
||||
"BaseSgmlLinkExtractor is deprecated and will be removed in future releases. "
|
||||
"Please use scrapy.linkextractors.LinkExtractor",
|
||||
ScrapyDeprecationWarning
|
||||
ScrapyDeprecationWarning, stacklevel=2,
|
||||
)
|
||||
SGMLParser.__init__(self)
|
||||
self.scan_tag = tag if callable(tag) else lambda t: t == tag
|
||||
|
|
@ -104,7 +104,7 @@ class SgmlLinkExtractor(FilteringLinkExtractor):
|
|||
warnings.warn(
|
||||
"SgmlLinkExtractor is deprecated and will be removed in future releases. "
|
||||
"Please use scrapy.linkextractors.LinkExtractor",
|
||||
ScrapyDeprecationWarning
|
||||
ScrapyDeprecationWarning, stacklevel=2,
|
||||
)
|
||||
|
||||
tags, attrs = set(arg_to_iter(tags)), set(arg_to_iter(attrs))
|
||||
|
|
|
|||
Loading…
Reference in New Issue