crawlo 1.4.4__py3-none-any.whl → 1.4.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of crawlo might be problematic. Click here for more details.

Files changed (120) hide show
  1. crawlo/__init__.py +11 -15
  2. crawlo/__version__.py +1 -1
  3. crawlo/commands/startproject.py +24 -0
  4. crawlo/core/engine.py +2 -2
  5. crawlo/core/scheduler.py +4 -4
  6. crawlo/crawler.py +8 -7
  7. crawlo/downloader/__init__.py +5 -2
  8. crawlo/downloader/cffi_downloader.py +3 -1
  9. crawlo/extension/__init__.py +2 -2
  10. crawlo/filters/aioredis_filter.py +8 -1
  11. crawlo/filters/memory_filter.py +8 -1
  12. crawlo/initialization/built_in.py +13 -4
  13. crawlo/initialization/core.py +5 -4
  14. crawlo/interfaces.py +24 -0
  15. crawlo/middleware/__init__.py +7 -4
  16. crawlo/middleware/middleware_manager.py +15 -8
  17. crawlo/middleware/proxy.py +171 -348
  18. crawlo/mode_manager.py +45 -11
  19. crawlo/network/response.py +374 -69
  20. crawlo/pipelines/mysql_pipeline.py +340 -189
  21. crawlo/pipelines/pipeline_manager.py +2 -2
  22. crawlo/project.py +2 -4
  23. crawlo/settings/default_settings.py +42 -30
  24. crawlo/stats_collector.py +10 -1
  25. crawlo/task_manager.py +2 -2
  26. crawlo/templates/project/items.py.tmpl +2 -2
  27. crawlo/templates/project/middlewares.py.tmpl +9 -89
  28. crawlo/templates/project/pipelines.py.tmpl +8 -68
  29. crawlo/templates/project/settings.py.tmpl +10 -55
  30. crawlo/templates/project/settings_distributed.py.tmpl +20 -22
  31. crawlo/templates/project/settings_gentle.py.tmpl +5 -0
  32. crawlo/templates/project/settings_high_performance.py.tmpl +5 -0
  33. crawlo/templates/project/settings_minimal.py.tmpl +25 -1
  34. crawlo/templates/project/settings_simple.py.tmpl +5 -0
  35. crawlo/templates/run.py.tmpl +1 -8
  36. crawlo/templates/spider/spider.py.tmpl +5 -108
  37. crawlo/tools/__init__.py +0 -11
  38. crawlo/utils/__init__.py +17 -1
  39. crawlo/utils/db_helper.py +226 -319
  40. crawlo/utils/error_handler.py +313 -67
  41. crawlo/utils/fingerprint.py +3 -4
  42. crawlo/utils/misc.py +82 -0
  43. crawlo/utils/request.py +55 -66
  44. crawlo/utils/selector_helper.py +138 -0
  45. crawlo/utils/spider_loader.py +185 -45
  46. crawlo/utils/text_helper.py +95 -0
  47. crawlo-1.4.6.dist-info/METADATA +329 -0
  48. {crawlo-1.4.4.dist-info → crawlo-1.4.6.dist-info}/RECORD +110 -69
  49. tests/authenticated_proxy_example.py +10 -6
  50. tests/bug_check_test.py +251 -0
  51. tests/direct_selector_helper_test.py +97 -0
  52. tests/explain_mysql_update_behavior.py +77 -0
  53. tests/ofweek_scrapy/ofweek_scrapy/items.py +12 -0
  54. tests/ofweek_scrapy/ofweek_scrapy/middlewares.py +100 -0
  55. tests/ofweek_scrapy/ofweek_scrapy/pipelines.py +13 -0
  56. tests/ofweek_scrapy/ofweek_scrapy/settings.py +85 -0
  57. tests/ofweek_scrapy/ofweek_scrapy/spiders/__init__.py +4 -0
  58. tests/ofweek_scrapy/ofweek_scrapy/spiders/ofweek_spider.py +162 -0
  59. tests/ofweek_scrapy/scrapy.cfg +11 -0
  60. tests/performance_comparison.py +4 -5
  61. tests/simple_crawlo_test.py +1 -2
  62. tests/simple_follow_test.py +39 -0
  63. tests/simple_response_selector_test.py +95 -0
  64. tests/simple_selector_helper_test.py +155 -0
  65. tests/simple_selector_test.py +208 -0
  66. tests/simple_url_test.py +74 -0
  67. tests/simulate_mysql_update_test.py +140 -0
  68. tests/test_asyncmy_usage.py +57 -0
  69. tests/test_crawler_process_import.py +39 -0
  70. tests/test_crawler_process_spider_modules.py +48 -0
  71. tests/test_crawlo_proxy_integration.py +8 -2
  72. tests/test_downloader_proxy_compatibility.py +24 -20
  73. tests/test_edge_cases.py +7 -5
  74. tests/test_encoding_core.py +57 -0
  75. tests/test_encoding_detection.py +127 -0
  76. tests/test_factory_compatibility.py +197 -0
  77. tests/test_mysql_pipeline_config.py +165 -0
  78. tests/test_mysql_pipeline_error.py +99 -0
  79. tests/test_mysql_pipeline_init_log.py +83 -0
  80. tests/test_mysql_pipeline_integration.py +133 -0
  81. tests/test_mysql_pipeline_refactor.py +144 -0
  82. tests/test_mysql_pipeline_refactor_simple.py +86 -0
  83. tests/test_mysql_pipeline_robustness.py +196 -0
  84. tests/test_mysql_pipeline_types.py +89 -0
  85. tests/test_mysql_update_columns.py +94 -0
  86. tests/test_optimized_selector_naming.py +101 -0
  87. tests/test_priority_behavior.py +18 -18
  88. tests/test_proxy_middleware.py +104 -8
  89. tests/test_proxy_middleware_enhanced.py +1 -5
  90. tests/test_proxy_middleware_integration.py +7 -2
  91. tests/test_proxy_middleware_refactored.py +25 -2
  92. tests/test_proxy_only.py +84 -0
  93. tests/test_proxy_with_downloader.py +153 -0
  94. tests/test_real_scenario_proxy.py +17 -17
  95. tests/test_response_follow.py +105 -0
  96. tests/test_response_selector_methods.py +93 -0
  97. tests/test_response_url_methods.py +71 -0
  98. tests/test_response_urljoin.py +87 -0
  99. tests/test_scrapy_style_encoding.py +113 -0
  100. tests/test_selector_helper.py +101 -0
  101. tests/test_selector_optimizations.py +147 -0
  102. tests/test_spider_loader.py +50 -0
  103. tests/test_spider_loader_comprehensive.py +70 -0
  104. tests/test_spiders/__init__.py +1 -0
  105. tests/test_spiders/test_spider.py +10 -0
  106. tests/verify_mysql_warnings.py +110 -0
  107. crawlo/middleware/simple_proxy.py +0 -65
  108. crawlo/tools/anti_crawler.py +0 -269
  109. crawlo/utils/class_loader.py +0 -26
  110. crawlo/utils/enhanced_error_handler.py +0 -357
  111. crawlo-1.4.4.dist-info/METADATA +0 -190
  112. tests/simple_log_test.py +0 -58
  113. tests/simple_test.py +0 -48
  114. tests/test_framework_logger.py +0 -67
  115. tests/test_framework_startup.py +0 -65
  116. tests/test_mode_change.py +0 -73
  117. {crawlo-1.4.4.dist-info → crawlo-1.4.6.dist-info}/WHEEL +0 -0
  118. {crawlo-1.4.4.dist-info → crawlo-1.4.6.dist-info}/entry_points.txt +0 -0
  119. {crawlo-1.4.4.dist-info → crawlo-1.4.6.dist-info}/top_level.txt +0 -0
  120. /tests/{final_command_test_report.md → ofweek_scrapy/ofweek_scrapy/__init__.py} +0 -0
@@ -3,142 +3,39 @@
3
3
  {{project_name}}.spiders.{{spider_name}}
4
4
  =======================================
5
5
  由 `crawlo genspider` 命令生成的爬虫。
6
- 基于 Crawlo 框架,支持异步并发、分布式爬取等功能。
7
-
8
- 使用示例:
9
- crawlo crawl {{spider_name}}
10
6
  """
11
7
 
12
8
  from crawlo.spider import Spider
13
9
  from crawlo import Request
14
- from ..items import ExampleItem
10
+ from ..items import {{item_class}}
15
11
 
16
12
 
17
13
  class {{class_name}}(Spider):
18
14
  """
19
15
  爬虫:{{spider_name}}
20
-
21
- 功能说明:
22
- - 支持并发爬取
23
- - 自动去重过滤
24
- - 错误重试机制
25
- - 数据管道处理
26
16
  """
27
17
  name = '{{spider_name}}'
28
18
  allowed_domains = ['{{domain}}']
29
19
  start_urls = ['https://{{domain}}/']
30
20
 
31
- # 高级配置(可选)
32
- # custom_settings = {
33
- # 'DOWNLOAD_DELAY': 2.0,
34
- # 'CONCURRENCY': 4,
35
- # 'RETRY_HTTP_CODES': [500, 502, 503, 504, 408, 429],
36
- # 'ALLOWED_RESPONSE_CODES': [200, 301, 302], # 只允许特定状态码
37
- # 'DENIED_RESPONSE_CODES': [403, 404], # 拒绝特定状态码
38
- # }
21
+ # 自定义设置(可选)
22
+ custom_settings = {}
39
23
 
40
24
  def start_requests(self):
41
25
  """
42
26
  生成初始请求。
43
-
44
- 支持自定义请求头、代理、优先级等。
45
27
  """
46
- headers = {
47
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
48
- 'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
49
- }
50
-
51
28
  for url in self.start_urls:
52
- yield Request(
53
- url=url,
54
- callback=self.parse,
55
- headers=headers,
56
- # meta={'proxy': 'http://proxy.example.com:8080'}, # 自定义代理
57
- # priority=10, # 请求优先级(数字越大优先级越高)
58
- )
29
+ yield Request(url=url, callback=self.parse)
59
30
 
60
31
  def parse(self, response):
61
32
  """
62
33
  解析响应的主方法。
63
-
64
- Args:
65
- response: 响应对象,包含页面内容和元数据
66
-
67
- Yields:
68
- Request: 新的请求对象(用于深度爬取)
69
- Item: 数据项对象(用于数据存储)
70
34
  """
71
35
  self.logger.info(f'正在解析页面: {response.url}')
72
36
 
73
- # ================== 数据提取示例 ==================
74
-
75
- # 提取数据并创建 Item
76
- # item = {{item_class}}()
77
- # item['title'] = response.xpath('//title/text()').get(default='')
78
- # item['url'] = response.url
79
- # item['content'] = response.xpath('//div[@class="content"]//text()').getall()
80
- # yield item
81
-
82
- # 直接返回字典(简单数据)
83
37
  yield {
84
38
  'title': response.xpath('//title/text()').get(default=''),
85
39
  'url': response.url,
86
40
  'status_code': response.status_code,
87
- # 'description': response.xpath('//meta[@name="description"]/@content').get(),
88
- # 'keywords': response.xpath('//meta[@name="keywords"]/@content').get(),
89
- }
90
-
91
- # ================== 链接提取示例 ==================
92
-
93
- # 提取并跟进链接
94
- # links = response.xpath('//a/@href').getall()
95
- # for link in links:
96
- # # 过滤有效链接
97
- # if link and not link.startswith(('javascript:', 'mailto:', '#')):
98
- # yield response.follow(
99
- # link,
100
- # callback=self.parse_detail, # 或者 self.parse 继续递归
101
- # meta={'parent_url': response.url} # 传递父页面信息
102
- # )
103
-
104
- # 用 CSS 选择器提取链接
105
- # for link in response.css('a.item-link::attr(href)').getall():
106
- # yield response.follow(link, callback=self.parse_detail)
107
-
108
- # ================== 分页处理示例 ==================
109
-
110
- # 处理分页
111
- # next_page = response.xpath('//a[@class="next"]/@href').get()
112
- # if next_page:
113
- # yield response.follow(next_page, callback=self.parse)
114
-
115
- # 数字分页
116
- # current_page = int(response.meta.get('page', 1))
117
- # max_pages = 100 # 设置最大页数
118
- # if current_page < max_pages:
119
- # next_url = f'https://{{domain}}/page/{current_page + 1}'
120
- # yield Request(
121
- # url=next_url,
122
- # callback=self.parse,
123
- # meta={'page': current_page + 1}
124
- # )
125
-
126
- def parse_detail(self, response):
127
- """
128
- 解析详情页面的方法(可选)。
129
-
130
- 用于处理从列表页跳转而来的详情页。
131
- """
132
- self.logger.info(f'正在解析详情页: {response.url}')
133
-
134
- # parent_url = response.meta.get('parent_url', '')
135
- #
136
- # yield {
137
- # 'title': response.xpath('//h1/text()').get(default=''),
138
- # 'content': '\n'.join(response.xpath('//div[@class="content"]//text()').getall()),
139
- # 'url': response.url,
140
- # 'parent_url': parent_url,
141
- # 'publish_time': response.xpath('//time/@datetime').get(),
142
- # }
143
-
144
- pass
41
+ }
crawlo/tools/__init__.py CHANGED
@@ -79,17 +79,6 @@ from .retry_mechanism import (
79
79
  exponential_backoff
80
80
  )
81
81
 
82
- # 反爬虫应对工具
83
- from .anti_crawler import (
84
- ProxyPoolManager,
85
- CaptchaHandler,
86
- AntiCrawler,
87
- get_random_user_agent,
88
- rotate_proxy,
89
- handle_captcha,
90
- detect_rate_limiting
91
- )
92
-
93
82
  # 带认证代理工具
94
83
  from .authenticated_proxy import (
95
84
  AuthenticatedProxy,
crawlo/utils/__init__.py CHANGED
@@ -4,6 +4,9 @@
4
4
  # @Time : 2025-02-05 13:57
5
5
  # @Author : oscar
6
6
  # @Desc : 工具模块集合
7
+
8
+ 提供用于处理parsel选择器的辅助函数,用于提取文本和属性等操作。
9
+ 所有方法都采用了简洁直观的命名风格,便于记忆和使用。
7
10
  """
8
11
 
9
12
  from ..tools.date_tools import (
@@ -20,6 +23,14 @@ from ..tools.date_tools import (
20
23
  from_timestamp_with_tz
21
24
  )
22
25
 
26
+ from .selector_helper import (
27
+ extract_text,
28
+ extract_texts,
29
+ extract_attr,
30
+ extract_attrs,
31
+ is_xpath
32
+ )
33
+
23
34
  __all__ = [
24
35
  "TimeUtils",
25
36
  "parse_time",
@@ -31,5 +42,10 @@ __all__ = [
31
42
  "to_timezone",
32
43
  "to_utc",
33
44
  "to_local",
34
- "from_timestamp_with_tz"
45
+ "from_timestamp_with_tz",
46
+ "extract_text",
47
+ "extract_texts",
48
+ "extract_attr",
49
+ "extract_attrs",
50
+ "is_xpath"
35
51
  ]