Want Faster HTTP Requests? Use A Session with Python!

  Рет қаралды 47,405

John Watson Rooney

John Watson Rooney

3 жыл бұрын

This is why I think you should use a http session when web scraping with python. It comes with many benefits and lets us access more features within the requests library, the most common and used Python library for http requests. In this video we look at the connection pooling that is allows us to access to speed up our code when sending requests to the same server. This is perfect for scraping data or accessing APIs.

Пікірлер: 94
@celerystalk390
@celerystalk390 3 жыл бұрын
Another great video covering an important topic for efficient web scraping. Thank you John!
@pr0skis
@pr0skis 3 жыл бұрын
Another fantastic vid! Short, succinct and very useful! I'll be applying this sessions thing to some of my code very shortly! As always, thanks for the great content.
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
Thank you!
@cetilly
@cetilly 3 жыл бұрын
Oh Jeesh. First day using the Session and it made a HUGE difference in performance (14 seconds for what used to take 2 minutes!). Thanks for covering this topic so well.
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
Great to hear!
@cetilly
@cetilly 3 жыл бұрын
Best vid on Requests.Session I've seen. Practical and very helpful
@GordonShamway1984
@GordonShamway1984 3 жыл бұрын
As always excellent work! Thank you so much to share your insights
@nikhil182
@nikhil182 Жыл бұрын
Thank you so much! I was looking for quick tutorial on keep-alive type of connections using requests library and this video solves my problem.
@ugurdev
@ugurdev 3 жыл бұрын
The wonders of internet in Australia, I am getting 46 seconds without and 38 with. haha. Good stuff, thanks John.
@tubelessHuma
@tubelessHuma 3 жыл бұрын
Nice short video to elaborate the efficiency of session object. 💖
@multigladiator384
@multigladiator384 2 жыл бұрын
Thanks again, John! Workwise I am "implementing" two different APIs'. They have rate limits and there is there case where I need to slice the input args and send multiple requests. This is how I will do it.
@nurshah816
@nurshah816 2 жыл бұрын
I was pretty amazed with Session performance, thanks a lot.
@katherinebaker3220
@katherinebaker3220 2 жыл бұрын
John, you are really cool. Your videos help me a lot!
@0xfsec
@0xfsec 3 жыл бұрын
Thank you so much for this Awesome tips John!
@avkngeeks
@avkngeeks 2 жыл бұрын
i really appreciate your lessons, the best on youtube
@abhijeetbonde8635
@abhijeetbonde8635 3 жыл бұрын
i was reading about sessions for 2 days and still couldn't understand the concept and just 7:15 minutes and i got a whole new level of knowledge... Thanks for the video buddy... really helped me...
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
No worries glad to help!
@easyshopping7264
@easyshopping7264 3 жыл бұрын
Thanks for your great effort, you are the teacher, with my regards , waleed
@KhalilYasser
@KhalilYasser 3 жыл бұрын
An awesome trick that will make difference certainly.
@darrenhuang2600
@darrenhuang2600 3 жыл бұрын
amazing video, helped out a lot
@i701Dev
@i701Dev 3 жыл бұрын
Great video. Thanks for this.
@potatopc
@potatopc Ай бұрын
this is life saving!!!
@thatguy6664
@thatguy6664 3 жыл бұрын
Another good one...cheers!
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
Thank you! Cheers!
@SkySesshomaru
@SkySesshomaru 2 жыл бұрын
Wow. Thank you bro!
@Klausi-uq4xq
@Klausi-uq4xq 3 жыл бұрын
Nice to know..such a difference..
@mehdismaeili3743
@mehdismaeili3743 Жыл бұрын
Excellent.
@JesusTorres-bt2eb
@JesusTorres-bt2eb 3 жыл бұрын
Amazing, you should do a video for scraping on a cloud flare website, but thank you
@rakshithrajesh3938
@rakshithrajesh3938 2 жыл бұрын
The Best Web Scraping Channel on KZfaq. He Teaches Each Topic so Clear and is very easy to Follow. Highly Recommend this Channel to anyone who wants to Learn Web Scraping the RIght Way. Keep it up John
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
Thank you very kind!
@alien9940
@alien9940 Жыл бұрын
Super helpful tip
@JohnWatsonRooney
@JohnWatsonRooney Жыл бұрын
Thanks! Check out my latest video if you liked this one much more on using the session
@Niki14741
@Niki14741 2 жыл бұрын
thats very helpful, thanks
@flimsy1417
@flimsy1417 2 жыл бұрын
great video :)
@Achiesamablog
@Achiesamablog 3 жыл бұрын
Maybe it is stupid question, but please bear with it as I am quite new to this. Will requests.Session() keep the session alive if I provide cookies and user agent (headers) to my requests, for example s.get(url, headers=headers, cookies=cookie) ? Will it still speed up my process? thank you for kind souls who will answer this question in advance. And thank you for the video too!
@primestarchannel7221
@primestarchannel7221 2 жыл бұрын
Great video, i tried it worked like a charm. Thank you. But when I do session.close and retry it says connection reset by peer. How to completely close the session?
@quangjoseph8287
@quangjoseph8287 2 жыл бұрын
Hi, i could get crsftoken from the cookies with Session for logging in Memrise website in 2021. But I don’t know why it doesn’t work the curent days. Could you please give me any advise?
@tanzimat2039
@tanzimat2039 2 жыл бұрын
Hey John,, thanks for the beautiful contents firstly
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
Hey! Generally no, you should always use a session, it won’t speed it up significantly enough to cause blocking
@Ervilhav10
@Ervilhav10 2 жыл бұрын
Nice video dude! Now my default way is session.get() instead of requests.get() hahaha
@HuskyTales2023
@HuskyTales2023 3 жыл бұрын
Hi can requests do sign-ups? I know it can do logins but what if we can send the sign up data thru post params.. besides the recaptcha token us a problem. Can you do a video to pass that kind of payload with recaptcha token
@lakshminarasimhanadimoorth3945
@lakshminarasimhanadimoorth3945 Жыл бұрын
Can we apply this to optionchain of Indian Stock Exchange(NSE) so that I can transfer the data to excel.
@campbat5712
@campbat5712 Жыл бұрын
Thanks, I went from 500 requests every 87 secconds to 500 requests every 33 secconds which is like the maxinum amount I can do considering the ratelimit
@erdemgunal13
@erdemgunal13 3 жыл бұрын
is there a way to get data from website has cloudflare ddos protection
@welcometout
@welcometout Жыл бұрын
I want to exit or close my session after my code complete its work. How to close the session at end of the code execution
@Automatic-show
@Automatic-show Жыл бұрын
John, in your opinion, which method works faster, session or concurrent.futures or asyncio ???? speed is one of the most important factors in this work.🤔🤔🤔🤔🤔🤔🤔
@rtxmax8223
@rtxmax8223 2 жыл бұрын
the requests library is working slow in my laptop (80 secs), when i run the same code it works fast in macbook (0.5 secs). What could be the issue ?
@DM-py7pj
@DM-py7pj 3 жыл бұрын
If you use gettitle_session(s , x) isn't s at this point a session object? So is there a reason for not passing it as an argument to the function v referencing globally?
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
Yes it is, we give the function out session object to use - you need to reference it outside the function though so every request uses the same session to make it cleaner and a bit faster
@aogunnaike
@aogunnaike 3 жыл бұрын
Very interesting
@maciekpaciarski9343
@maciekpaciarski9343 3 жыл бұрын
Hi .when can one expect new live web scraping with python ?
@novianindy887
@novianindy887 Жыл бұрын
Does the session literally means creating application session in server then append session-cookies in every of its get request? or it means TCP session via Keep-Alive connection?
@novianindy887
@novianindy887 Жыл бұрын
I mean the requests.Session()
@axelamoe
@axelamoe Жыл бұрын
Can you show us how to handle required cookies by a site?
@dalefixter
@dalefixter 2 жыл бұрын
when using pytest, can the session be persisted in the test, when the session had been created in a conftest fixture?
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
My initial thoughts are yes, I can see that you could do so within the same session but it’s not something I’ve done before, my experience with pytest is limited
@glenn8781
@glenn8781 2 жыл бұрын
I love how you just slipped in 'pip install requests' as a text overlay in the beginning of the video 😂
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
😅 thanks
@indhumathi7391
@indhumathi7391 2 жыл бұрын
Can session used for 504 Gateway timeout error in Python API?
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
No a 504 is a server error not a client one so it won’t solve that issue
@pahadivillager5354
@pahadivillager5354 3 жыл бұрын
Nice video! How do we close this session without using the "with" keyword?
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
Session.close() I believe!
@islamibrahim4735
@islamibrahim4735 3 жыл бұрын
Very nice, can you make video on how to scrap LinkedIn Jobs based on profession and salary using scrapy
@tushargupta5890
@tushargupta5890 9 ай бұрын
My code improved by 75 %
@hlrn4141
@hlrn4141 6 ай бұрын
Would you still recommend session over httpx?
@JohnWatsonRooney
@JohnWatsonRooney 6 ай бұрын
Httpx has its own session object too
@manikandanmanickam9433
@manikandanmanickam9433 3 жыл бұрын
Pls do scraping to for the Delta airlines website
@PolSenserrich
@PolSenserrich Жыл бұрын
Don't you have to close the session every time??
@gouemoregis195
@gouemoregis195 3 жыл бұрын
Here we go
@mr.strange7002
@mr.strange7002 2 жыл бұрын
HELP !! I am using pythons request lib and I want to get data from an API .. so I write down a program and run it on my local computer it just run perfectly .. but when I try to like host the code in web like heroku or in replit it responds with status code 200 but not providing data inside the api... I tried to change the user agent as a browser agent but it doesn't worked.. can anyone help me out..
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
A 200 response could still be a captcha page or similar - try checking to what information is coming back, however it’s likely being blocked as your now on an IP shared with lots and lots of other people
@mr.strange7002
@mr.strange7002 2 жыл бұрын
@@JohnWatsonRooney It's return a json string with two keys like message : ok & Type : ok in webhost but when I try the exactly same code with same bearer token and headers on local computer it provides the entire json file with all the data ... How can I fix this ...
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
Is it an api with an actual key or from web scraping?
@mr.strange7002
@mr.strange7002 2 жыл бұрын
@@JohnWatsonRooney It's an API with authentication token and headers
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
That’s odd. Im not sure, sorry!
@nooral-firdaus7144
@nooral-firdaus7144 2 жыл бұрын
Unfortunately, it did not work for me. With or without session, the running time is the same... :-(
@JohnWatsonRooney
@JohnWatsonRooney 2 жыл бұрын
Really? Ok fair enough. To go faster you’ll need to learn about async and await
@deepak2950
@deepak2950 3 жыл бұрын
Why my session is taking more time than normal
@aiisnice1453
@aiisnice1453 3 жыл бұрын
Or you can do that: from concurrent.futures import ThreadPoolExecutor def FetchAllListing(page): print(page) r = requests.get(f"rei.com/c/backpacks?json=true&page={ page }") with ThreadPoolExecutor(max_workers=30) as e:#Threads e.map(FetchAllListing, range(50) )#Amount of pages to scrap
@kenkelvin4023
@kenkelvin4023 3 жыл бұрын
Nice
@bestpoppers7369
@bestpoppers7369 3 жыл бұрын
Good idea
@Christian-mn8dh
@Christian-mn8dh Жыл бұрын
ly bro
@kenkelvin4023
@kenkelvin4023 3 жыл бұрын
Use pypy3, it’s what I use along with golang
@bunyaminsahiner9060
@bunyaminsahiner9060 3 жыл бұрын
hello. thank you so much for this wonderful tip. I would like to use this session. My .py similar to your 'Web Scraping with Python: Ecommerce Product Pages. In Depth including troubleshooting' video .py How I can add in this codes? there are 2 requests. first for find links, second for products data.
@anikahmed7456
@anikahmed7456 3 жыл бұрын
Please make video on regex
@JohnWatsonRooney
@JohnWatsonRooney 3 жыл бұрын
Good idea
@mnsvcar9900
@mnsvcar9900 11 ай бұрын
I prefer time.time() for calculating time elapsed. Shorter.
@Shankar_Vasudevan
@Shankar_Vasudevan Жыл бұрын
HTMLSession is better than requests.Session()
@ErikS-
@ErikS- Жыл бұрын
You forget to close the session that you created. Bad practice. Instead you should use a python context...
@hh3739
@hh3739 3 жыл бұрын
use gevent or muti threading are super more quicker than session
@kenkelvin4023
@kenkelvin4023 3 жыл бұрын
Clearly haven’t heard of multithreading eh?
@tubelessHuma
@tubelessHuma 3 жыл бұрын
Nice short video to elaborate the efficiency of session object. 💖
Python Asyncio, Requests, Aiohttp | Make faster API Calls
17:56
Patrick Collins
Рет қаралды 127 М.
Working With APIs in Python - Pagination and Data Extraction
22:36
John Watson Rooney
Рет қаралды 96 М.
Clowns abuse children#Short #Officer Rabbit #angel
00:51
兔子警官
Рет қаралды 73 МЛН
ЧУТЬ НЕ УТОНУЛ #shorts
00:27
Паша Осадчий
Рет қаралды 8 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 111 МЛН
Request Headers for Web Scraping
10:03
John Watson Rooney
Рет қаралды 45 М.
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 604 М.
Web Scraping with Python and BeautifulSoup is THIS easy!
15:51
Thomas Janssen | Tom's Tech Academy
Рет қаралды 23 М.
The most important Python script I ever wrote
19:58
John Watson Rooney
Рет қаралды 170 М.
Requests Library in Python - Beginner Crash Course
20:32
NeuralNine
Рет қаралды 45 М.
Web Scraping with ChatGPT is mind blowing 🤯
8:03
Code Bear
Рет қаралды 39 М.
Python requests p.1 (status_code, headers, body, get, post)
24:11
python samurai
Рет қаралды 48 М.
The Biggest Mistake Beginners Make When Web Scraping
10:21
John Watson Rooney
Рет қаралды 106 М.
Requests vs HTTPX vs Aiohttp | Which One to Pick?
15:11
ArjanCodes
Рет қаралды 35 М.
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 15 МЛН
Какой ноутбук взять для учёбы? #msi #rtx4090 #laptop #юмор #игровой #apple #shorts
0:18
Look, this is the 97th generation of the phone?
0:13
Edcers
Рет қаралды 4,8 МЛН
АЙФОН 20 С ФУНКЦИЕЙ ВИДЕНИЯ ОГНЯ
0:59
КиноХост
Рет қаралды 1,1 МЛН
Смартфон УЛУЧШАЕТ ЗРЕНИЕ!?
0:41
ÉЖИ АКСЁНОВ
Рет қаралды 1,2 МЛН
iPhone socket cleaning #Fixit
0:30
Tamar DB (mt)
Рет қаралды 15 МЛН
Как правильно выключать звук на телефоне?
0:17
Люди.Идеи, общественная организация
Рет қаралды 1,8 МЛН