Beautiful Soup 4 Tutorial #1 - Web Scraping With Python

Поделиться
HTML-код
  • Опубликовано: 4 июн 2024
  • Welcome to a new tutorial series on Beautiful Soup 4! Beautiful Soup 4 is a web scraping module that allows you to get information from HTML documents and modify them as well. It's very versatile and there is a lot of things to go over and in this video, I'll be giving an introduction/walkthrough to Beautiful Soup 4.
    💻 AlgoExpert is the coding interview prep platform that I used to ace my Microsoft and Shopify interviews. Check it out and get a discount on the platform using the code "techwithtim" algoexpert.io/techwithtim
    📄 Resources 📄
    Beautiful Soup Docs: www.crummy.com/software/Beaut...
    Code In This Video: github.com/techwithtim/Beauti...
    Fix Pip (Mac): • How to Install Pygame ...
    Fix Pip (Windows): • How to Install Pygame ...
    NewEgg Link: www.newegg.ca/gigabyte-geforc...
    📚 Playlist: • Beautiful Soup 4 Tutor...
    ⭐️ Timestamps ⭐️
    00:00 | Overview
    01:26 | Beautiful Soup 4 Setup
    02:51 | Reading HTML Files
    05:50 | Find By Tag Name
    07:45 | Find All By Tag Name
    09:44 | Parsing Website HTML
    12:50 | Locating Text
    13:53 | Beautiful Soup Tree Structure
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    💰 Courses & Merch 💰
    💻 The Fundamentals of Programming w/ Python: tech-with-tim.teachable.com/p...
    👕 Merchandise: teespring.com/stores/tech-wit...
    🔗 Social Medias 🔗
    📸 Instagram: / tech_with_tim
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-ruscica-82631b179
    🌎 Website: techwithtim.net
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    🎬 My RUclips Gear 🎬
    🎥 Main Camera (EOS Canon 90D): amzn.to/3cY23y9
    🎥 Secondary Camera (Panasonic Lumix G7): amzn.to/3fl2iEV
    📹 Main Lens (EFS 24mm f/2.8): amzn.to/2Yuol5r
    🕹 Tripod: amzn.to/3hpSprv
    🎤 Main Microphone (Rode NT1): amzn.to/2HrZxXc
    🎤 Secondary Microphone (Synco Wireless Lapel System): amzn.to/3e07Swl
    🎤 Third Microphone (Rode NTG4+): amzn.to/3oi0v8Z
    ☀️ Lights: amzn.to/2ApeiXr
    ⌨ Keyboard (Daskeyboard 4Q): amzn.to/2YpN5vm
    🖱 Mouse (Logitech MX Master): amzn.to/2HsmRDN
    📸 Webcam (Logitech 1080p Pro): amzn.to/2B2IXcQ
    📢 Speaker (Beats Pill): amzn.to/2XYc5ef
    🎧 Headphones (Bose Quiet Comfort 35): amzn.to/2MWbl3e
    🌞 Lamp (BenQ E-reading Lamp): amzn.to/3e0UCr8
    🌞 Secondary Lamp (BenQ Screenbar Plus): amzn.to/30Dtafi
    💻 Monitor (BenQ EX2780Q): amzn.to/2HsmUPZ
    💻 Monitor (LG Ultrawide 34WN750): amzn.to/3dSD7tS
    🎙 Mic Boom Arm (Rode PSA 1): amzn.to/30EZw9m
    🎚 Audio Interface (Focusrite Scarlet 4i4): amzn.to/2TjXsih
    💸 Donations 💸
    💵 One-Time Donations: www.paypal.com/donate?hosted_...
    💰 Patreon: / techwithtim
    ◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
    ⭐️ Tags ⭐️
    - Tech With Tim
    - Beautiful Soup 4
    - Web Scraping
    - HTML
    - HTML Parsing
    - Python
    ⭐️ Hashtags ⭐️
    #TechWithTim #BeautifulSoup4

Комментарии • 316

  • @dariyababumalapati7144
    @dariyababumalapati7144 Год назад +79

    The 'text' argument is changed into 'string' in Beautiful Soup 4.4.0.

    • @DetectiveConan990v3
      @DetectiveConan990v3 Год назад

      yes thank you

    • @IanWeingardt
      @IanWeingardt 4 месяца назад

      thank you so much, I was very lost when I got the "DepacrationWarning"

    • @parvpaigwar2925
      @parvpaigwar2925 8 дней назад

      @@IanWeingardt It appears that the content might be dynamically loaded by JavaScript in amazon website, which means it might not be present in the initial HTML response

  • @adnanpramudio6109
    @adnanpramudio6109 2 года назад +119

    I started learning python few months ago and chose web scraping as my specialization. Your selenium playlist is fascinating. Thanks Tim

    • @mihailmilenkov6223
      @mihailmilenkov6223 2 года назад

      Hey how did you progress?

    • @AliAhmed63708
      @AliAhmed63708 2 года назад +1

      r u currently freelancing webscraping ?

    • @alex59292
      @alex59292 Год назад +1

      @@AliAhmed63708 i am

    • @hjvela1907
      @hjvela1907 Год назад

      @@alex59292 So where can I reach you for some webscraping freelancing.

  • @unpatel1
    @unpatel1 2 года назад +3

    I was puhsing learning web scraping for some time now and finally jumped in today and watched my first video on this topic. I like Tim's videos because they are simple and easy to underatsnd, so I decided to go with his video on this topc. Thank you.

  • @hydrocrazynik76
    @hydrocrazynik76 2 года назад +12

    Such a great tutorial! I usually don't comment but this was absolutely spectacular. Thank you so much!

  • @Recklessness97
    @Recklessness97 10 месяцев назад +3

    Subscribed. The last 4 minutes of the video is exactly what I needed. The Soup tree structure part, specifically dissecting the price out of the HTML code. I could get the price on my own web scrap script but it also came with a bunch of other "junk" that was apart of the "tree". Thanks for pointing me in the right direction and explaining how it works!!!!!

  • @tanmaypatel4152
    @tanmaypatel4152 2 года назад +77

    Man I was literally looking for a good tutorial on Bs4 and guess what Tim read my mind. Thank you very much Tim :)

    • @BB-si6cz
      @BB-si6cz 2 года назад +3

      And I started with web scraping like 2 days ago

    • @tanmaypatel4152
      @tanmaypatel4152 2 года назад +1

      @@BB-si6cz Oh that's cool !

    • @Damiensgarage
      @Damiensgarage 2 года назад

      Deffo RUclips AI reading your mind maybe it was Alexa

    • @tanmaypatel4152
      @tanmaypatel4152 2 года назад

      @@Damiensgarage I was already subscribed to Tim so I got the notification :)

    • @melodyparker3485
      @melodyparker3485 2 года назад

      I'm pretty sure that Corey Schafer also has a good tutorial about beautiful soup.

  • @igordc16
    @igordc16 2 года назад +5

    Straight forward, simple explanations , easy to follow. Thanks Tim! You're a excellent teacher, keep up the great work you're doing here on youtube.

  • @toshitsingh7270
    @toshitsingh7270 2 года назад +1

    As always your tutorials are super educational and also thanks teaching it for free, it really helps.

  • @jimstand
    @jimstand 2 года назад +1

    SO I am writing some software to start a business. I am scraping 25 web pages. I hacked through the first 20. The last 5 were difficult so I tried using BS4 with this video. Using BS4 made the last 5 easier than any of the first 20. Thank you Tim!!

  • @as_below_so_above
    @as_below_so_above 2 года назад +1

    Great video and great timing to put it out! I had to use BeautifulSoup for the first time just last week and this was great at solidifying everything I learned!

  • @selo2410
    @selo2410 2 года назад +2

    THANK YOU, I've been waiting for you to make a tutorial on this for some time now, thanks again.

  • @oskarwallberg4566
    @oskarwallberg4566 2 года назад

    Beautiful video man! Just realised how pedagogical and well dispositioned you videos are.

  • @neroplus-it
    @neroplus-it 2 года назад +3

    your videos on web scraping motivated me to create my own video-series about this topic(s)! as always, great content! thanks for sharing your knowledge.

  • @kristaandrews3405
    @kristaandrews3405 Год назад +1

    I'm using Anaconda, so had to use different import information. You explained this better then any video I've watched.

  • @MrBobman82
    @MrBobman82 2 года назад

    Tim I just started scraping with BS4 THANK YOU!

  • @Khyreemlb
    @Khyreemlb 2 года назад +1

    Amazing stuff man. You got yourself a new sub. Thank you for all of the content and hard work. I've been benging all of your videos like I was watching Netflix lol

  • @proxyscrape
    @proxyscrape Год назад

    Great tutorial Tim! I appreciate the clear and concise explanations you provided.

  • @romanv4519
    @romanv4519 2 года назад

    Awesome tutorial. New to this channel, but I like your style Tim. Thanks a lot, very well explained!

  • @Mallan_
    @Mallan_ Год назад

    Many thanks. I was struggling with scraping some links from a page but couldn't until I watched this video.

  • @sampsondzameshie-sb3ek
    @sampsondzameshie-sb3ek Год назад +1

    Hi, l love all your videos boss.
    Thank you very much.
    I do not have an IT background but fell in love with your videos and started studying Software development in school right now.

  • @thec-m
    @thec-m 2 года назад +7

    This was a really useful tutorial and it was clear to understand, unlike some of the other videos I found. Thank you! I'm sure there are many people out there like me that find themselves trying to slightly improve their code, resulting in learning how to use some new massive python library like this.
    Back to the video: I think it would have been good to replace the URL at the end of the video with another NewEgg listing to show the same code extracting a different price (assuming the tags are the same). Also, looks like you forgot to edit out the part at 8:24.

  • @namename-cl8kk
    @namename-cl8kk 2 года назад +3

    Finaly the best timing ever i was waiting it plz speedeun that series

  • @Said664016
    @Said664016 Год назад

    The best tutorial ever! You're saving my life!

  • @ezekomaugoo5569
    @ezekomaugoo5569 Год назад

    Quite a very concise course and informative. Thanks for this guide.

  • @tieutantan9562
    @tieutantan9562 2 года назад +1

    This serial is my need. Thank Tim!

  • @rahulxdd
    @rahulxdd 2 года назад +8

    Thank you Tim. I always wanted to learn Beautiful soup for personal projects but never did. Today is the first time I watched a tutorial on this topic. Anyway, how long will this series be? Can't wait for the next part.

  • @nightwind132
    @nightwind132 2 года назад +1

    god that 3080 price gave me stress of when I was hunting down my own. Great tutorial btw it's been a great help!

  • @markslima1557
    @markslima1557 Год назад +1

    Thank you this video is so straightforward I think I finally got the hang of this

  • @matrix26uk
    @matrix26uk 2 года назад

    1 quick point to add about BS4 not installing. Sometimes being connected to a VPN can stop modules being installed. Try dropping off the VPN and running Tims install commands

  • @hmodexl
    @hmodexl 2 года назад

    ur explanations are very clear,thank for ur effort.

  • @loisvallee7291
    @loisvallee7291 2 года назад +2

    need this to access my uni's timetable more easily, thanks man !

  • @derelictmanchester8745
    @derelictmanchester8745 Год назад +1

    Love your channel Tim, the best tutorial ever..

  • @davevanemmenes27
    @davevanemmenes27 Год назад

    Congrats on your 1 million,
    All the best

  • @user-wt2rn1ki9n
    @user-wt2rn1ki9n 2 года назад +24

    "Dummy html file"
    The html file who is trying his best: 😿👍

  • @philippededeken4881
    @philippededeken4881 Год назад

    Great video. Thanks to you, I'm starting a new business in the tyre industry.

  • @dbstudio7859
    @dbstudio7859 Год назад +2

    def amazing():
    while 1:
    print("Thanks Tim")
    amazing()

  • @Spleed7887
    @Spleed7887 2 года назад +11

    Dude, I think you should do more C++ tutorials. They're really good!

    • @elpython3471
      @elpython3471 2 года назад +1

      I second this. Those tuts are good!

  • @RandyWatson80
    @RandyWatson80 2 года назад

    As always, this was super clear

  • @jacobfuller5643
    @jacobfuller5643 Год назад

    super helpful for a project I am working on, thanks!

  • @BonVoyageWorld
    @BonVoyageWorld Год назад

    you should have more than "just" 1,18m subscribers. thank you Sir!

  • @wlqpqpqlqmwnhssisjw6055
    @wlqpqpqlqmwnhssisjw6055 2 года назад +1

    I am good in Bs4 But I just came to give you like .For your work

  • @b07x
    @b07x 2 года назад

    Thanks, this was easier than I thought

  • @PeterPankowski
    @PeterPankowski 2 месяца назад

    Excellent done for a first example! Amazing explained!

  • @anwar587
    @anwar587 2 года назад

    Web scraping is very useful trust me and of course beautifulsoup is the best library for this

  • @Knuddelfell
    @Knuddelfell 2 года назад +1

    exactly needed this

  • @ChrisOfTheOutdoors
    @ChrisOfTheOutdoors Год назад +2

    Anybody know why I would be getting "IndexError: list index out of range" on line 10 - "parent = prices[0].parent" at the 15:29 minute mark in the video? I've copied the whole code exactly.

    • @abssdabss
      @abssdabss Год назад

      make sure your url is correct

  • @thisischarismatic
    @thisischarismatic 10 месяцев назад

    Absolutely great videos, I’m new to python and coding in general. Your content is really great and easy to follow, would this web scraping method work for finding stuff like meta data for songs ?

  • @julianaschmidt1059
    @julianaschmidt1059 Год назад +1

    So useful! Thank you so much!

  • @danielmarx3106
    @danielmarx3106 2 года назад

    Is there a benefit/difference in using .string vs .text to grab the text of a tag? I always have used .text. Thanks!

  • @guy6567
    @guy6567 2 года назад

    Thanks Tim! :) awesome and helpful

  • @prof.code-dude2750
    @prof.code-dude2750 2 года назад +1

    I wanted to create a BS4 project 😀 and you made a tutorial

  • @AmbiNerd
    @AmbiNerd 2 года назад

    wooo wooo thanks TIM huge help!

  • @learnwitharbia3477
    @learnwitharbia3477 Год назад

    Thank you so much for such valuable content

  • @laurasasso8798
    @laurasasso8798 2 года назад

    Perfect ! Thank you

  • @BiologyIsHot
    @BiologyIsHot 2 года назад

    Is there a way to scrape text generated by something like ReactJS with BS4? Usually it doesn't properly return that HTML even if you can see it in the inspector.

  • @pokedreadhead6089
    @pokedreadhead6089 Год назад

    So sick thanks for the video!

  • @keifer7813
    @keifer7813 2 года назад +1

    8:25 It's always fun seeing bloopers mid video lol

  • @popey747
    @popey747 Год назад

    Wonderful to be learning Beautiful Soup with Kermit

  • @greening6904
    @greening6904 2 года назад

    Tim you wont believe i was working on a meteo app and needed a parser thx

  • @zawadahmed5484
    @zawadahmed5484 2 года назад

    Keep on your beautiful contents

  • @alejandrogenio100
    @alejandrogenio100 Год назад +1

    hey tim great work , i need to learn how to do using python columns and boxes in visual studio code thanks very much .

  • @hollowr9953
    @hollowr9953 2 года назад

    Interesting video, as always

  • @friday8118
    @friday8118 Год назад +2

    How do we input the html or the website we want to scrape? Great video, thank you.

  • @ilbike8068
    @ilbike8068 Год назад

    I have question I am making we scrapping with beautiful soup and selenium. I wrote everything there is just one mistake. Beautifulsoup undefined? I installed everything what can I do ?

  • @codewith7360
    @codewith7360 2 года назад

    Hey Tim, What to do for the content that is dynamic??

  • @DGHere12
    @DGHere12 2 года назад

    thx for this tutorial, tim

  • @83yWasTooShort
    @83yWasTooShort Год назад

    Really useful, cheers

  • @fuadpalchayev7269
    @fuadpalchayev7269 Год назад

    Thank you very much!

  • @scottdol2099
    @scottdol2099 2 года назад +1

    Great stuff as usual! What's the schedule for the next episodes?

  • @thesocksv2483
    @thesocksv2483 Год назад

    Thanks you a lot, you're the best.

  • @jamiemorrissey2858
    @jamiemorrissey2858 2 года назад

    Nice, good video, learned a lot

  • @mohitupadhayay1439
    @mohitupadhayay1439 2 года назад

    Hi Tim,
    Can you help out for scraping pages which have CAPTCHA and also where there are contents in same tags but I want to get data from say just first tag instead of other four.
    This is kinda like python loc [0]
    Please help!

  • @AmirRTR
    @AmirRTR 26 дней назад

    best guy on yt

  • @RonaldPostelmans
    @RonaldPostelmans Год назад

    Hi Tim, nice video, need stuff. have you any links to a tutorial of you or else someone, who has scraped websites that block scrapers?

  • @CarlosPerez3dArt
    @CarlosPerez3dArt 2 года назад

    Super cool you are so helpful

  • @tildesarecool7782
    @tildesarecool7782 2 года назад

    I was following along with this video and couldn't get it to work. Actually I was following along but with my public "all games" steam library page. I couldn't figure out why it wasn't work. I was losing my mind. Then I finally saw in the source this JavaScript block with formatted data for all my games. It's "DB Query" and also the JS appends the data to the DOM programmatically. So indirectly this video taught me why Beautiful Soup couldn't find the tags I kept searching for on the steam library page. Side note, anyone want to scrape their steam library for some reason (instead of using steam db or whatever) it's all there on that page as some kind of JSON.
    Good video btw.

  • @almaghror1
    @almaghror1 2 года назад

    Thanks Tim

  • @FreAcker
    @FreAcker Год назад +3

    hey, just updating.
    find_all(text=) is deprecated
    switch to string= method instead;)

  • @garybenhart
    @garybenhart 7 месяцев назад +9

    Unfortunately, the code mentioned in the video at 13:15 no longer seems to work, probably because NewEgg no longer allows a Python script to download the htlm from web site pages. It seems to me that most web sites are being "bot protected" today, a problem that is specifically mentioned by Tim in the video at 11:25. This points to a very significant problem when you consider using a tool like Python to web scrape, because using standard Python code is not ever going to work.
    Finally, when you do get lucky and get your Python code to web scrape, that code that works perfectly today will probably not work very long.

    • @AsuGhimire
      @AsuGhimire 6 месяцев назад

      real, its a struggle to learn when you're trying to debug and its just privacy policies in your html files xD

  • @andrealcantara1437
    @andrealcantara1437 Год назад +15

    I'm trying in a different website. I can get the HTML, but when I try to look for specific texts it doesn't work, I always get an empty list, even though I can see that there is that text in the page.

    • @labscience8271
      @labscience8271 Год назад +2

      Same problem. Did you find a solution?

    • @hamzayunusa2224
      @hamzayunusa2224 Год назад

      @@labscience8271 did u find one?

    • @abdulrahmanal-saadani8769
      @abdulrahmanal-saadani8769 Год назад +3

      I have the same problem but if you noticed in the video he said that some websites may block you when you try to script their html page so maybe the is the reason why you get an empty list

    • @DauvO
      @DauvO Год назад +1

      @@abdulrahmanal-saadani8769 I have the same problem.. but I think that if the html can be seen in the console in the previous steps, that means the robots haven't done any blocking? I would think if you can see the data that's gameover once you learn how to manipulate it.

    • @AnibalDellagiovanna
      @AnibalDellagiovanna 10 месяцев назад

      For me it only work if you look for the hall test in the element. For ejemaple The full text" will not work for "full" or "The full". It only work if you search "The full test". You can test it with a local HTML file. Is not the web filtering it.

  • @mamadturaan
    @mamadturaan 2 года назад

    USEFUL !

  • @romaintisserand8921
    @romaintisserand8921 Год назад

    Nice, thank you ^^

  • @mmbaguette1520
    @mmbaguette1520 2 года назад +3

    Hey Tim, can you make a video on how to get a programming job? 👋

  • @acutisnasus7217
    @acutisnasus7217 2 года назад

    8:26 Oh nooo,... you're in the matrix. You glitched!!!
    Top tutorial!!!

  • @sushmaravi9122
    @sushmaravi9122 2 года назад

    Hearty thanks

  • @beratsamil
    @beratsamil 2 года назад

    thanks Tim! :D

  • @Darthdeedee91
    @Darthdeedee91 2 года назад

    btw what's the difference between all the different ways to install? using pip vs pip3 vs adding the python etc.?? Trying to understand the terminal

  • @sebschewenk2504
    @sebschewenk2504 2 года назад

    Hei I'm working with VS Code studio. If I'm trying to print(doc) and run the program it just shows me that it was successful. The doc itself doesn't get printed. Does anybody know what to do? Do I have to install some kind of extension in VS Code Studio?

  • @ScriptureFirst
    @ScriptureFirst Год назад

    outstanding walkthru, as usual, ty... I like the chapter divisions, concise talking, maximized screen, text size :)

  • @altrumilusiom
    @altrumilusiom Год назад

    Hello Tim, I was wondering I tried this script with microcenter. When I get to the tag where the price is on, I tried to print the tag.string it returns "None" ?????. but when I use tag.text it returns the price Why is that?

  • @pavelpenshin2871
    @pavelpenshin2871 2 года назад

    What IDE / Editor do you use here and in your videos?

  • @chris1232123
    @chris1232123 Год назад

    How come doing 'parent' on the $ sign returned so many layers of tags? Why was it not just the tags directly surrounding?

  • @mousemeister
    @mousemeister 2 года назад

    nice editing job and content ofc thx

  • @derangeddoffy
    @derangeddoffy 2 года назад

    Does this series teach you basically what you need to know or is it only just bare basics?

  • @jalepenofatty6704
    @jalepenofatty6704 2 года назад

    great video , hit a bunch of roadblocks with the imports and environment %PATH% changes i had to make, and then the openssl issue, but yeah took me a day to get thru this and finish, i appreciate the hardwork.

    • @unpatel1
      @unpatel1 2 года назад +1

      Glad that you finally solved your problem! Me too, had a hard time with the %PATH% thingy!@$$. Time to time %PATH% problem appears from no where and eats up lots of my time. I have worked a little with R and I found it relatively simple and easy in this aspect, package installation and management etc...

    • @andrews9168
      @andrews9168 2 года назад +1

      @@unpatel1 another workaround is to use pycharm

    • @unpatel1
      @unpatel1 2 года назад +1

      @@andrews9168 Thank you for your suggestion. I do have pycharm but not using it, just use VS Code all the time. I will definitely try pycharm.

  • @lioraharon6352
    @lioraharon6352 11 месяцев назад

    What if the html page has invisible element and you need to click on element and then it can be visible and parsed?
    In selenium you have to click on the element
    With beautiful soup can you get this element even if it invisible?

  • @alagappank1242
    @alagappank1242 2 года назад

    Superb...🤩

  • @prodigyprogrammer3269
    @prodigyprogrammer3269 2 года назад +2

    8:23 did you forget to edit 😂😂
    love your videos BTW ❤️

  • @JohnTackett01
    @JohnTackett01 Год назад

    Which dev environment are you using for this?

  • @aleebboy
    @aleebboy 2 года назад

    thanks tim!