看的太难受了...
[Asm] 纯文本查看 复制代码 import aiofiles,aiohttp,asyncio,time
from lxml import etree
async def get(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
res=await resp.text()
return res
async def xr(url,aa,dz):
res=await get(url)
ress=etree.HTML(res)
a=ress.xpath('//*[@id="content"]/text()')
for i in a:
async with aiofiles.open(rf'{dz}\{aa}.txt','a',encoding='utf-8') as f:
await f.write(i.strip())
print(f'第{aa}章下好啦')
async def zy(pid):
dz=input('请输入您要保存的地址:')
aa=0
taks=[]
new_url=f'https://www.biqugeu.net{pid}'
res=await get(new_url)
ress=etree.HTML(res)
a=ress.xpath('//*[@id="list"]/dl//a/@href')
for i in range(12,len(a)):
aa+=1
urll=f'https://www.biqugeu.net{a}'
taks.append(asyncio.create_task(xr(urll,aa,dz)))
await asyncio.wait(taks)
async def main(name):
res=await get(f'https://www.biqugeu.net/searchbook.php?keyword={name}')
ress=etree.HTML(res)
a=ress.xpath('//*[@id="hotcontent"]/div/div/dl/dt/a/@href')[0]
await zy(a)
if __name__=='__main__':
name=input('请输入您要下载的书名:')
time1=time.time()
loop = asyncio.get_event_loop()
loop.run_until_complete(main(name))
time2=time.time()
print(f'下载完成啦,一共用了{time2-time1}s')
input('Press Enter to exit…') |