Es ist in Ordnung, aber wenn ich versuche, eine nicht blockierende App zu erstellen (warten), blockiert beautifulsoup4 die Anwendung (weil beautifulsoup4 Async nicht unterstützt)
Das habe ich versucht.
Code: Select all
import asyncio, aiohttp
from bs4 import BeautifulSoup
async def extractLinks(html):
soup = BeautifulSoup(html, 'html.parser')
return soup.select(".c-pro-box__title a")
async def getHtml(session, url):
async with session.get(url) as response:
return await response.text()
async def loadPage(url):
async with aiohttp.ClientSession() as session:
html = await getHtml(session, url)
links = await extractLinks(html)
return links
loop = asyncio.get_event_loop()
loop.run_until_complete(loadPage())
Ist es also möglich, ihn nicht blockierend zu machen? Oder gibt es außer beautifulsoup4 eine Bibliothek, die Async so gut wie möglich unterstützt?
Mobile version