Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
liangbaika committed Jan 12, 2021
1 parent 6cce944 commit 09b5a52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion smart/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def start(self):

if resp is None:
# let the_downloader can be scheduled, test 0.001-0.0006 is better
await asyncio.sleep(0.005)
await asyncio.sleep(0.0005)
continue

custome_callback = resp.request.callback
Expand Down
4 changes: 4 additions & 0 deletions smart/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AioHttpDown(BaseDown):

async def fetch(self, request: Request) -> Response:
session = None
resp = None
try:
session = request.session or aiohttp.ClientSession()
resp = await session.request(request.method,
Expand All @@ -53,8 +54,11 @@ async def fetch(self, request: Request) -> Response:
cookies=resp.cookies
)
finally:
if resp:
resp.release()
if request.session is None and session:
await session.close()

return response


Expand Down
6 changes: 6 additions & 0 deletions spiders/govs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
# Date: 2021/1/6
# Desc: there is a python file description
# ------------------------------------------------------------------
import asyncio
import traceback

import aiohttp

from smart.field import HtmlField
from smart.item import Item
from smart.request import Request
Expand All @@ -27,6 +30,7 @@ class GovsSpider(Spider):
"http://www.nea.gov.cn/policy/jd.htm"
]


def parse(self, response: Response):
selects_detail_urls = response.xpath(
'//*[@class="list"]//li//a/@href').getall()
Expand All @@ -45,3 +49,5 @@ def parse_detail(self, response):

def on_exception_occured(self, e: Exception):
print(e)


0 comments on commit 09b5a52

Please sign in to comment.