Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/findimage.py
2020-10-11 15:49:09 +08:00

25 lines
674 B
Python

import re
import traceback
import aiohttp
from bs4 import BeautifulSoup as bs
async def findimage(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as req:
if req.status != 200:
return None
else:
q = await req.text()
try:
soup = bs(q, 'html.parser')
aa = soup.find('div', id='mw-content-text')
src = aa.find_all('div', class_='fullImageLink')
z = re.match('.*<a href="(.*)"><.*', str(src), re.S)
find = re.sub(r'\?.*', '', z.group(1))
return find
except Exception:
traceback.print_exc()
return None