本文整理汇总了Python中wpull.scraper.HTMLScraper.is_supported方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLScraper.is_supported方法的具体用法?Python HTMLScraper.is_supported怎么用?Python HTMLScraper.is_supported使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wpull.scraper.HTMLScraper
的用法示例。
在下文中一共展示了HTMLScraper.is_supported方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_by_record
# 需要导入模块: from wpull.scraper import HTMLScraper [as 别名]
# 或者: from wpull.scraper.HTMLScraper import is_supported [as 别名]
def convert_by_record(self, url_record):
'''Convert using given URL Record.'''
filename = url_record.filename
if not os.path.exists(filename):
return
if url_record.link_type:
if url_record.link_type not in ('css', 'html'):
return
else:
link_type = url_record.link_type
else:
with open(filename, 'rb') as in_file:
if HTMLScraper.is_supported(
file=in_file, url_info=url_record.url_info):
link_type = 'html'
elif CSSScraper.is_supported(
file=in_file, url_info=url_record.url_info):
link_type = 'css'
else:
link_type = None
_logger.info(__(
_('Converting links in file ‘{filename}’ (type={type}).'),
filename=filename, type=link_type
))
if self._backup_enabled:
shutil.copy2(filename, filename + '.orig')
temp_filename = filename + '-new'
if link_type == 'css':
self._css_converter.convert(
filename, temp_filename, base_url=url_record.url)
elif link_type == 'html':
self._html_converter.convert(
filename, temp_filename, base_url=url_record.url)
else:
raise Exception('Unknown link type.')
os.remove(filename)
os.rename(temp_filename, filename)
示例2: convert_by_record
# 需要导入模块: from wpull.scraper import HTMLScraper [as 别名]
# 或者: from wpull.scraper.HTMLScraper import is_supported [as 别名]
def convert_by_record(self, url_record):
'''Convert using given URL Record.'''
filename = self._path_namer.get_filename(
URLInfo.parse(url_record.url)
)
if not os.path.exists(filename):
return
if url_record.link_type:
if url_record.link_type not in ('css', 'html'):
return
else:
link_type = url_record.link_type
else:
with open(filename, 'rb') as in_file:
if HTMLScraper.is_supported(
in_file, url_info=url_record.url_info):
link_type = 'html'
elif CSSScraper.is_supported(
in_file, url_info=url_record.url_info):
link_type = 'css'
else:
link_type = None
_logger.info(
_('Converting links in file ‘{filename}’ (type={type}).')\
.format(filename=filename, type=link_type)
)
if self._backup_enabled:
shutil.copy2(filename, filename + '.orig')
if link_type == 'css':
self._css_converter.convert(
filename, filename, base_url=url_record.url)
elif link_type == 'html':
self._html_converter.convert(
filename, filename, base_url=url_record.url)