Skip to Content
Advanced Python Programming
book

Advanced Python Programming

by Dr. Gabriele Lanaro, Quan Nguyen, Sakis Kasampalis
February 2019
Intermediate to advanced
672 pages
16h 50m
English
Packt Publishing
Content preview from Advanced Python Programming

Fetching a website's HTML code

First, let's look at how to make a request and obtain the HTML source code from a single website with aiohttp. Note that even with only one task (a website), our application remains asynchronous, and the structure of an asynchronous program still needs to be implemented. Now, navigate to the Chapter11/example4.py file, as follows:

# Chapter18/example4.pyimport aiohttpimport asyncioasync def get_html(session, url):    async with session.get(url, ssl=False) as res:        return await res.text()async def main():    async with aiohttp.ClientSession() as session:        html = await get_html(session, 'http://packtpub.com')        print(html)loop = asyncio.get_event_loop()loop.run_until_complete(main())

Let's consider the main() coroutine ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Advanced Python Programming - Second Edition

Advanced Python Programming - Second Edition

Quan Nguyen
Expert Python Programming - Third Edition

Expert Python Programming - Third Edition

Michał Jaworski, Tarek Ziadé, Cody Jackson
Expert Python Programming - Fourth Edition

Expert Python Programming - Fourth Edition

Michał Jaworski, Tarek Ziade, Tarek Ziadé

Publisher Resources

ISBN: 9781838551216Supplemental Content