기사님, 알 아 보 세 요.
import requests as req
from bs4 import BeautifulSoup
import lxml
import re
import os
import aiohttp
import asyncio
u="D:/test"
if not os.path.exists(u):
os.mkdir(u)
base_url="http://www.hkdsz.com/art-type-id-{page}-pg-{num}.html"
temp_url="http://www.hkdsz.com"
async def job(p):
urls=[base_url.format(page=p,num=x) for x in range(1,3)]
for url in urls:
htmlone=req.get(url).text
soup_one=BeautifulSoup(htmlone,features='lxml')
pages=soup_one.find('div',{'class':'box list channel'}).find('ul').find_all('a')
for y in pages:
title=y['title'].split()
title=str(title).replace(':','').replace('!','').replace('?','').replace(',','').replace(' ','')
print(title)
new_url=temp_url+y['href']
htmltwo=req.get(new_url).text
souptwo=BeautifulSoup(htmltwo,features='lxml')
img_urls=souptwo.find('div',{'class':'novelContent'}).find('img')
img_base_url=s=str(img_urls['src']).split("-")[0]
t=souptwo.find('div',{'class':'pagination'}).find_all('a',{'class':'pagelink_a'})[1]
max=str(t).split("-")[-1].split(".")[0]
n=0
try:
os.mkdir(u+"/"+title)
except Exception as e:
continue
for z in range(1,int(max)+1):
n=n+1
new_url=img_base_url+"-"+str(z)+".jpg"
html=req.get(new_url,timeout=7)
with open(u+"/"+title+"/"+str(n)+".jpg",'wb') as f:
f.write(html.content)
asyncio.sleep(1)
async def main(loop):
tasks = [loop.create_task(job(x)) for x in range(0,8)]
await asyncio.wait(tasks)
loop=asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로마 숫자를 정수로 또는 그 반대로 변환그 중 하나는 로마 숫자를 정수로 변환하는 함수를 만드는 것이었고 두 번째는 그 반대를 수행하는 함수를 만드는 것이었습니다. 문자만 포함합니다'I', 'V', 'X', 'L', 'C', 'D', 'M' ; 문자열이 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.