coocan 0.5.6__py3-none-any.whl → 0.5.6.1__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.
- coocan/_examples/use_proxy.py +22 -0
- coocan/push_project.py +1 -1
- coocan/url/request.py +19 -4
- {coocan-0.5.6.dist-info → coocan-0.5.6.1.dist-info}/METADATA +1 -4
- {coocan-0.5.6.dist-info → coocan-0.5.6.1.dist-info}/RECORD +8 -7
- {coocan-0.5.6.dist-info → coocan-0.5.6.1.dist-info}/WHEEL +1 -1
- {coocan-0.5.6.dist-info → coocan-0.5.6.1.dist-info}/entry_points.txt +0 -0
- {coocan-0.5.6.dist-info → coocan-0.5.6.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
from coocan import Request, Response, MiniSpider
|
2
|
+
|
3
|
+
|
4
|
+
class UseProxySpider(MiniSpider):
|
5
|
+
start_urls = ["https://httpbin.org/ip"]
|
6
|
+
max_requests = 5
|
7
|
+
delay = 5
|
8
|
+
|
9
|
+
def start_requests(self):
|
10
|
+
proxy = "http://127.0.0.1:1082"
|
11
|
+
yield Request(self.start_urls[0], callback=self.parse, proxy=proxy)
|
12
|
+
|
13
|
+
def middleware(self, request: Request):
|
14
|
+
request.headers["Referer"] = "https://httpbin.org"
|
15
|
+
|
16
|
+
def parse(self, response: Response):
|
17
|
+
print(response.status_code, response.json())
|
18
|
+
|
19
|
+
|
20
|
+
if __name__ == '__main__':
|
21
|
+
s = UseProxySpider()
|
22
|
+
s.go()
|
coocan/push_project.py
CHANGED
coocan/url/request.py
CHANGED
@@ -7,22 +7,37 @@ cli = httpx.AsyncClient()
|
|
7
7
|
|
8
8
|
|
9
9
|
class Request:
|
10
|
-
def __init__(
|
10
|
+
def __init__(
|
11
|
+
self,
|
12
|
+
url: str, callback: Callable = None, cb_kwargs=None,
|
13
|
+
params=None, headers=None,
|
14
|
+
data=None, json=None,
|
15
|
+
proxy=None, timeout=6,
|
16
|
+
priority=None
|
17
|
+
):
|
11
18
|
self.url = url
|
12
19
|
self.callback = callback
|
20
|
+
self.cb_kwargs = cb_kwargs or {}
|
13
21
|
self.params = params
|
14
22
|
self.headers = headers or {}
|
15
23
|
self.data = data
|
16
24
|
self.json = json
|
25
|
+
self.proxy = proxy
|
17
26
|
self.timeout = timeout
|
18
|
-
self.cb_kwargs = cb_kwargs or {}
|
19
27
|
self.priority = priority or time.time()
|
28
|
+
self.__client = None
|
29
|
+
|
30
|
+
@property
|
31
|
+
def client(self):
|
32
|
+
if self.proxy is None:
|
33
|
+
return cli
|
34
|
+
return httpx.AsyncClient(proxy=self.proxy)
|
20
35
|
|
21
36
|
async def send(self):
|
22
37
|
if (self.data and self.json) is None:
|
23
|
-
response = await
|
38
|
+
response = await self.client.get(self.url, params=self.params, headers=self.headers, timeout=self.timeout)
|
24
39
|
elif self.data or self.json:
|
25
|
-
response = await
|
40
|
+
response = await self.client.post(self.url, params=self.params, headers=self.headers, data=self.data, json=self.json, timeout=self.timeout)
|
26
41
|
else:
|
27
42
|
raise Exception("仅支持 GET 和 POST 请求")
|
28
43
|
return response
|
@@ -1,8 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: coocan
|
3
|
-
Version: 0.5.6
|
3
|
+
Version: 0.5.6.1
|
4
4
|
Summary: Air Async Spider Framework
|
5
|
-
Author: wauo
|
6
5
|
Author-email: wauo <markadc@126.com>
|
7
6
|
License-Expression: MIT
|
8
7
|
Project-URL: Homepage, https://github.com/markadc/coocan
|
@@ -11,8 +10,6 @@ Description-Content-Type: text/markdown
|
|
11
10
|
Requires-Dist: click>=8.0.0
|
12
11
|
Requires-Dist: httpx
|
13
12
|
Requires-Dist: loguru
|
14
|
-
Dynamic: author
|
15
|
-
Dynamic: requires-python
|
16
13
|
|
17
14
|
# 项目说明
|
18
15
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
coocan/__init__.py,sha256=R1gUEUP9v_2iA1gE5twrxr-XRnPhP9EFftLrDeudAoA,53
|
2
2
|
coocan/gen.py,sha256=4MCE3t24m3-rbq2snAzByPe58VAo-ShWn58iXpcEiBE,995
|
3
|
-
coocan/push_project.py,sha256=
|
3
|
+
coocan/push_project.py,sha256=5filLp6ol_W7NapcvB3kHFlBm5Nq_6kYS0eb9mo0RbI,249
|
4
4
|
coocan/_examples/crawl_csdn_detail.py,sha256=S3lGihGZF-6KI_Kg5H23BQ9cVzOkZwKrS78n1lYOcAg,1830
|
5
5
|
coocan/_examples/crawl_csdn_list.py,sha256=D7j5W0WM_52PoWv-2KLuts2r4rabMXavbMS3wnIg6Gk,1454
|
6
6
|
coocan/_examples/recv_item.py,sha256=Iym6RbvL7j87SvK14Hw2Exvxx047jEF4zQV9yo4ZXF4,976
|
7
|
+
coocan/_examples/use_proxy.py,sha256=nybPmGHKvn3ZX6yICukDYtXW0NXfyFSrICeaD2rMNP4,575
|
7
8
|
coocan/_examples/view_local_ip.py,sha256=AcatCwtFF6NeYdzbvD8SXun0wn0IL0pX2D3GWUlQ0Sc,560
|
8
9
|
coocan/cmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
10
|
coocan/cmd/cli.py,sha256=T7U0QUtAC3O_ZAsglZoOo3nqUPmfceJWbkdso-SwI18,2412
|
@@ -11,10 +12,10 @@ coocan/spider/__init__.py,sha256=nqERS5a5eSgJfBiIp5moZvwS6JOToNCM_4kreRrtmaQ,57
|
|
11
12
|
coocan/spider/base.py,sha256=C26B7orcmGczVDq8MmAVH_VCgEQ17gszBZQaXflXkzg,6165
|
12
13
|
coocan/templates/spider.txt,sha256=1wcbmnv9mBi-21pdygDMukiMy6lEAbvYVRhVOfNY99k,463
|
13
14
|
coocan/url/__init__.py,sha256=KN0lLNVaAISoITrPyjD2HOf2A9UYb-9Bbw4xfs9Zqk4,100
|
14
|
-
coocan/url/request.py,sha256=
|
15
|
+
coocan/url/request.py,sha256=1b7K3rDMxH9_LCx9yfoUART_Ntzm16kbCDjSMOE7wAM,1386
|
15
16
|
coocan/url/response.py,sha256=ruIzOcFcJqszTmbNV9y1BSxdWeyVydsMJd-cDMTJHLo,1735
|
16
|
-
coocan-0.5.6.dist-info/METADATA,sha256=
|
17
|
-
coocan-0.5.6.dist-info/WHEEL,sha256=
|
18
|
-
coocan-0.5.6.dist-info/entry_points.txt,sha256=hNdk42NPboC1o7s7GzMbpII5t2U2jWrtT5bpvliXRcw,47
|
19
|
-
coocan-0.5.6.dist-info/top_level.txt,sha256=VwB-Q4zEljgb9v1Ms1E59B-1pBYORXuhKjgZb-LHOhk,7
|
20
|
-
coocan-0.5.6.dist-info/RECORD,,
|
17
|
+
coocan-0.5.6.1.dist-info/METADATA,sha256=toWhwGXOQhdU9Y2UBs2ltj-deB8hEX82jIT2nVKX0_o,2364
|
18
|
+
coocan-0.5.6.1.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
19
|
+
coocan-0.5.6.1.dist-info/entry_points.txt,sha256=hNdk42NPboC1o7s7GzMbpII5t2U2jWrtT5bpvliXRcw,47
|
20
|
+
coocan-0.5.6.1.dist-info/top_level.txt,sha256=VwB-Q4zEljgb9v1Ms1E59B-1pBYORXuhKjgZb-LHOhk,7
|
21
|
+
coocan-0.5.6.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|