File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,17 @@ def __iter__(self):
485
485
def __next__ (self ):
486
486
return self ._next (fetch = True , next_symbol = self .next_symbol ).html
487
487
488
+ def __aiter__ (self ):
489
+ return self
490
+
491
+ async def __anext__ (self ):
492
+ while True :
493
+ url = self ._next (fetch = False , next_symbol = self .next_symbol )
494
+ if not url :
495
+ break
496
+ response = await self .session .get (url )
497
+ return response .html
498
+
488
499
def add_next_symbol (self , next_symbol ):
489
500
self .next_symbol .append (next_symbol )
490
501
Original file line number Diff line number Diff line change 1
- from requests_html import HTMLSession
1
+ import pytest
2
+ from requests_html import HTMLSession , AsyncHTMLSession
2
3
3
4
session = HTMLSession ()
4
5
6
+
5
7
def test_pagination ():
6
8
pages = (
7
9
'https://xkcd.com/1957/' ,
@@ -14,3 +16,17 @@ def test_pagination():
14
16
r = session .get (page )
15
17
assert next (r .html )
16
18
19
+
20
+ @pytest .mark .asyncio
21
+ async def test_pagination (event_loop ):
22
+ asession = AsyncHTMLSession ()
23
+ pages = (
24
+ 'https://xkcd.com/1957/' ,
25
+ 'https://reddit.com/' ,
26
+ 'https://smile.amazon.com/' ,
27
+ 'https://theverge.com/archives'
28
+ )
29
+
30
+ for page in pages :
31
+ r = await asession .get (page )
32
+ assert await r .html .__anext__ ()
You can’t perform that action at this time.
0 commit comments