-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
36 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
[tool.poetry] | ||
name = "scrapy-kit" | ||
version = "0.1.12" | ||
name = "spider-tool-kit" | ||
version = "0.1.0" | ||
description = "" | ||
authors = ["Pony.Ma <[email protected]>"] | ||
readme = "README.md" | ||
packages = [{include = "scrapy_kit"}] | ||
homepage = "https://scrapy-kit.readthedocs.io/en/latest/" | ||
documentation = "https://scrapy-kit.readthedocs.io/en/latest/" | ||
repository = "https://github.com/ma-pony/scrapy-kit" | ||
packages = [{include = "spider_tool_kit"}] | ||
homepage = "https://spider-tool-kit.readthedocs.io/en/latest/" | ||
documentation = "https://spider-tool-kit.readthedocs.io/en/latest/" | ||
repository = "https://github.com/ma-pony/spider-tool-kit" | ||
license = "Apache-2.0" | ||
keywords = ["scrapy", "scrapy-kit", "scrapy-kit"] | ||
keywords = ["spider", "scrapy", "scrapy-kit", "spider-kit", "spider-tools", "spider-tool-kit"] | ||
|
||
|
||
[tool.poetry.dependencies] | ||
|
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ENCODINGS = ['latin1', 'cp1252', 'iso-8859-1', 'gbk', 'ascii'] |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .text_encode import * |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from spider_tool_kit.contants import ENCODINGS | ||
|
||
|
||
def fix_encode(garbled_text: str, decoding='utf-8') -> (str, str): | ||
""" | ||
修复乱码 | ||
:param garbled_text: 乱码文本 | ||
:param decoding: 解码方式 | ||
:return: 正常文本, 编码 | ||
""" | ||
for encoding in ENCODINGS: | ||
try: | ||
res = garbled_text.encode(encoding).decode(decoding) | ||
return res, encoding | ||
except (UnicodeEncodeError, UnicodeDecodeError): | ||
continue |
File renamed without changes.
File renamed without changes.
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
Empty file.
Empty file.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from spider_tool_kit.tools import fix_encode | ||
|
||
|
||
class TestTextEncode: | ||
def test_fix_encode(self): | ||
garbled_text = "亿元" | ||
expected_text = "亿元" | ||
expected_encoding = "cp1252" | ||
result = fix_encode(garbled_text) | ||
assert result == (expected_text, expected_encoding) |