Python: Real Time Stock Price Scraping and Plotting with Beautiful Soup and Matplotlib Animation

Поделиться
HTML-код
  • Опубликовано: 27 ноя 2024

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

  • @jayhiryu2139
    @jayhiryu2139 3 года назад +3

    I was building this from scratch and trying to figure out a way to do this im glad i found this video

  • @capitalcool3162
    @capitalcool3162 4 года назад +8

    This is exactly what I am looking for. Excellent!

  • @coenbushwool6968
    @coenbushwool6968 4 года назад +3

    Pulling out data and automatically plotting them, love it!

    • @clarknikolai9739
      @clarknikolai9739 3 года назад

      I know it is kinda randomly asking but do anybody know of a good website to watch newly released movies online?

    • @tomasscott7088
      @tomasscott7088 3 года назад

      @Clark Nikolai Try flixzone. You can find it by googling =)

    • @terrancejeffrey6175
      @terrancejeffrey6175 3 года назад

      @Tomas Scott Yup, I have been using flixzone for since april myself :D

    • @clarknikolai9739
      @clarknikolai9739 3 года назад

      @Tomas Scott thanks, I went there and it seems like a nice service :D I appreciate it!

    • @tomasscott7088
      @tomasscott7088 3 года назад

      @Clark Nikolai you are welcome xD

  • @pratikghimire
    @pratikghimire 4 года назад +3

    Thank you. I will use this concept in my personal project.

  • @wheelman6964
    @wheelman6964 4 года назад +5

    Great tutorial!
    To change searches with common Western symbols/stocks (MSFT, AAPL): change "+ stock_code + ('?p=') + stock_code + ('&.tsrc=fin-srch')"

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад +3

      Great point to facilitate others to tailer-made their own portfolio. I hope you don't mind if I pin your comment for others' reference. Thanks.

    • @wheelman6964
      @wheelman6964 4 года назад +2

      @@eMasterClassAcademy My pleasure.

  • @ramankr0022
    @ramankr0022 3 года назад

    thanku, at last found something very helpful. thankyou thank you thank you

  • @rickybiotrue2363
    @rickybiotrue2363 4 года назад +1

    Excellent work!

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

    Very interesting video. A bit over my head. I'll stick with yfinance for now. I will download the video and study it some more.

  • @python360
    @python360 4 года назад +2

    Nice video - I did similar last year with a Rapsberry Pi and had the prices display on LED matrix !

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад

      hi Dr. Pi, just checked out your applications. That's so cool! I like the LED setting concept. You could even use that for setting up an alarm or signals when prices reach certain levels.

    • @python360
      @python360 4 года назад

      @@eMasterClassAcademy Yes, I had a buzzer attached, and it buzzed every 30 secs when it displayed a different stock.
      If I was to redo it, I'd probably get a red and a blue LED and flash the price on red if price had dropped, blue if it had gone up.
      I had it plugged in and CRON made the script start up at 8am when the stock exchange opened.

  • @fannykwan5672
    @fannykwan5672 4 года назад

    The visualisation is cool!

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

    Pretty cool.......

  • @jayeshsuthar8161
    @jayeshsuthar8161 4 года назад +2

    Great tutorial

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

    Incredible, keep doing more tutorials

  • @ch0tu
    @ch0tu 3 года назад +1

    beautiful shup❤️

  • @pennydog97
    @pennydog97 4 года назад +2

    Thanks for the tutorial! I do have a question, I am able to scrape and generate the .csv file. However, when I run the animate script, theres no realtime animation, it seems to just plot the current time/price in the csv file. This occurs for both jupyter notebook and spyder. Did anyone else encounter this?
    style.use('fivethirtyeight')
    fig, ax = plt.subplots()
    def animate(i):
    df = pd.read_csv('test.csv')
    ys = df.iloc[1:, 2].values
    xs = list(range(1, len(ys) + 1))
    ax.clear()
    ax.plot(xs, ys)
    ax.set_title("btc")
    ani = animation.FuncAnimation(fig, animate, interval = 1000)
    plt.tight_layout()
    plt.show()

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад +1

      Thanks for your sharing. I was just wondering whether you are running both programmes at the same time. On one hand, 1) you scrape and save updates. On the other hand, 2) you read saved updates and generate plot.
      And then you keep these two processes, i.e. 1) and 2), continue running.
      But I applied it in PyCharm, so, I am really not sure whether it has problems in Jupyter. So I do appreciate your feedback and hope it helps others.

    • @dineshlakshmanan7104
      @dineshlakshmanan7104 4 года назад +2

      Use %matplotlib notebook...

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

    how can I check for the correlation between the tweets and the stock prices?

  • @ThutaMyanmar1
    @ThutaMyanmar1 3 года назад

    Can the website server shut down by fetching data from this websites in x second. I am thinking if the users are too much request in every second to this stock website, which can lead to server down? I am working a kind of software project like this and thinking future performance

  • @anthonychung2907
    @anthonychung2907 3 года назад

    The animation 4 plots at the begining looks very good , but that looks very different from the results plots at the end of this video?

  • @lightuncharged9525
    @lightuncharged9525 3 года назад +1

    please help when I am trying to scrap content, the output is showing "none"

  • @idkwhatonamethiseriously
    @idkwhatonamethiseriously 3 года назад

    I wanted to get a graph for history of the stock, but I'm stuck at the inspection step. I've got the right block but how do I get the values in it?

  • @shivanshsingh5555
    @shivanshsingh5555 4 года назад +1

    why you have used df.T?
    Why we need to transpose it?

  • @PadulAmador
    @PadulAmador 3 года назад

    Good content. But please: don't make me sleep in your class again.

  • @sirchu5074
    @sirchu5074 4 года назад

    This is an interesting project!

  • @shekharkumar1902
    @shekharkumar1902 3 года назад +1

    While ploting graph I am getting error " value error: could not convert string to float" though the value I am getting in csv file is integer .

    • @patrisch2539
      @patrisch2539 3 года назад

      if you scrape from internet a number can be a string, because it is written text you copied. you can easily convert it.
      a variable can hold a 2 or a '2'.

  • @shekharkumar1902
    @shekharkumar1902 3 года назад

    I am having same problem and it's problem for many of us who tried to apply this tutorial i.e. 'NoneType' object has no attribute 'find'. Please suggest

  • @financeunlimited8118
    @financeunlimited8118 4 года назад +1

    Data is the new oil!

  • @abdulhaq1742
    @abdulhaq1742 4 года назад +1

    This is really interesting, It would be very helpful if you show how to send this scraped data to email when we reach a price level.

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад +1

      This is a extremely great suggestion! Really appreciate with your advice and will definitely try it out.

    • @abdulhaq1742
      @abdulhaq1742 4 года назад

      @@eMasterClassAcademy Thank you will be looking for it.

  • @ramankr0022
    @ramankr0022 3 года назад

    i have one doubt, why are there websites in which we can see a class named 'something' inside inspect element but cant search it in source code? are some things hidden in page source code??

  • @shernjlow3559
    @shernjlow3559 3 года назад

    THANKS

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

    I would be very grateful if you could tell me why I always got same price, price no change at all after run the code

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

      Thanks for watching.
      There are some updates in the backend and HTML code in Yahoo Finance. So, we need to revise some codes accordingly.
      Please check out my latest video for web scraping - ruclips.net/video/A9Rj77CKpJ8/видео.html
      Hope this helps.

  • @faalihmyusa1720
    @faalihmyusa1720 3 года назад

    Please help,
    I cant do this on jupyter notebook. It always collect the data first, and show the plot after that. Can we do real time plotting on jupyter notebook?

  • @asithafernando8395
    @asithafernando8395 3 года назад +1

    when i srapping yahoo finance it gives same values at all, but in the yahoo finance page, it is changing,

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

      The same thing is happening. After re-running the script, the data is not updated.

  • @surendrasharma7246
    @surendrasharma7246 3 года назад +1

    Sir I m from India. Can you provide nse India or any broker Api development like this format. Thnx in advance

  • @aditisaptarishy6956
    @aditisaptarishy6956 4 года назад

    This is an amazing video made by you. But I have the doubt regarding HSI. If stock code is like ^NSEI, then what should be there in HSI list?

  • @nxli97
    @nxli97 4 года назад

    Quick question:
    What's the difference between using 'html.parser' and 'lxml' in the BeautifulSoup function?

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад +4

      The main difference is about speed. In general, lxml is faster than the html.parser.
      However, speed should not the main criteria for determining which parser that you are going to use. You should focus on the HTML document, and use the praser that works in your particular websites. Because sometimes, one works while the others give you "none" result.
      So, I will often try 1) lxml, 2) html.parser and 3) html5lib.
      Details can be found in Beautiful Soup website. www.crummy.com/software/BeautifulSoup/bs4/doc/#differences-between-parsers

  • @rohitnikam307
    @rohitnikam307 4 года назад +1

    Sir how to make option chain analysis setup in python

  • @maximiliankrug1011
    @maximiliankrug1011 3 года назад

    Really Nice Work, is there a possibillity to combine the two programs into one?

    • @eMasterClassAcademy
      @eMasterClassAcademy  3 года назад

      Thanks for your comment. I was thinking it's not possible, because we need to combine the "for loop"/"while loop" in the first program and "while loop" (animate) in the second program.
      Or something like "break the program" and "restart" it again? Seems not that straight forward.

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

      @@eMasterClassAcademy Multitreading or Multiprocessing should be a solution for that task.

  • @AIstepbystep366
    @AIstepbystep366 3 года назад

    You could use yfinance library to get prices

    • @eMasterClassAcademy
      @eMasterClassAcademy  3 года назад +1

      Yes, this is a good API.
      My whole point here is to show web scraping, because some websites are useful, but they don't offer any API.
      Also, if we need more frequent interval, like less than 1 min data. the yfinance library can't help.
      But I agree with you, yfinance is a good substitute.

  • @shauryamisra5924
    @shauryamisra5924 4 года назад +1

    it still shows me nonetype has no attribute find

  • @JAKKOtutorials
    @JAKKOtutorials 4 года назад

    hey i got it going, scraping, saving the csv but when i plot the data my graph only rises, goes up, even if the next value is smaller than the previous one... i checked like a 1000 times your code and mine comparing, and i can't find what the hell is wron lol, if someone knows what's going on, please let me know :)

    • @JAKKOtutorials
      @JAKKOtutorials 3 года назад +1

      @Jamie Cliffe hey! yeah i figured that out eventually researching it in other places... but thanks, your comment will definitely help others who might have this issue! 😊

  • @marchosetiawan2151
    @marchosetiawan2151 4 года назад

    i got a problem while try to use the BeautifulSoup(r.text, 'lxml')
    Traceback (most recent call last):
    File "D:/Roullete/roulletegraph.py", line 9, in
    web_content = BeautifulSoup(r.text, 'lxml')
    File "D:\Roullete\venv\lib\site-packages\bs4\__init__.py", line 243, in __init__
    raise FeatureNotFound(
    bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
    does anyone know why?

    • @dennischuangdz
      @dennischuangdz 3 года назад

      try changing the 'lxml' into 'html.parser'

  • @mohamedabdo-xg6tw
    @mohamedabdo-xg6tw Год назад

    Thank you for your patience.
    Our engineers are working quickly to resolve the issue.
    I am watching in April 2023 and it seems like yahoo don't want people to scrape their site. the request end with the two P tags above, and there is no element to scrape when you do r.text.

  • @cw9249
    @cw9249 3 года назад

    this code doesnt work, it says animate() takes 0 positional arguments but 1 was given

  • @mydetlef
    @mydetlef 3 года назад

    What about the source code? Or should everyone type it themselves?

  • @Pradeep_prasad
    @Pradeep_prasad 3 года назад

    Animate doesn't support 3.8 version what I do

  • @Gho0O0ost35
    @Gho0O0ost35 3 года назад

    I did the same for a website. However problem with this is process time getting more and more.. So it takes data later. Few minutes later lag is becoming like 15-20 seconds. Has anyone a solution for that ?

  • @pucek365
    @pucek365 3 года назад +1

    I have quite a big problem with this script, because it does not update the data while running which is wierd and I don't know why it happens, Can anyone help me?

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

      The same thing is happening. After re-running the script, the data is not updated.

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

      @@KulikovValery Hey man, glad you found my comment, I solved the issue using completely different method. I used a library called yahoo_fin and from that library I used module called stock_ info
      There is a method where you can get live prices of stocsk that are of your interest in one line of code.

  • @chankwongyin7455
    @chankwongyin7455 4 года назад

    Thank you for your class! Do you come from Hong Kong?

  • @Tehguy1
    @Tehguy1 4 года назад

    great video! In the video, you pulled price for HK only. Yet when you ran the application, it pulled prices for CLP, CKH, HSBC etc. How do you run multiple prices in the same column? I tried doing stock_code = "CHK", "HK" etc but i got errors

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад

      Hi, what are the stock that you are looking for?
      What I am doing is to use stock code ['0001', '0002', '0003', '0005'] to represent different stocks, and then append them into the column one by one respectively, then append them into row one by one according to the timestamp.
      The most difficult parts when you are using the beautiful soup to do web scrapping are 1) identifying the correct link and 2) identifying the correct ''tag'/div'.

    • @Tehguy1
      @Tehguy1 4 года назад

      @@eMasterClassAcademy
      I'm using T, AAPL, KO and XOM. I can only seem to pull the data for T. I'll rewatch your video and see if I can get it.
      Thanks

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад

      @@Tehguy1 Please see Robert Navarro's comment. I pinned it. He kindly provided the changes in code for Western symbols/stocks. Wish it helps.

    • @Tehguy1
      @Tehguy1 4 года назад

      @@eMasterClassAcademy thanks. i was able to get that part. but my question is, how do you associate the different symbols for his, when you do 0001, 0002, 0003, and 0004 with the different stock code

  • @shivanshsingh5555
    @shivanshsingh5555 4 года назад

    at @19:18 why you have use index 1 in iloc?

  • @ignaciogonzalez6179
    @ignaciogonzalez6179 4 года назад

    Nice video interesting!!! I am having a problem with web_content.find as an AttributeError: "NoneType" object has no attribute "find" ??

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад

      Hi, very often, if you find the wrong 'div' / tag, then you will get the "NoneType". So I suggest you keep trying different 'div', especially for those upper level tag.

    • @shekharkumar1902
      @shekharkumar1902 3 года назад

      I am having same problem and it's problem for many of us who tried to apply this tutorial i.e. 'NoneType' object has no attribute 'find'. This problem occurred when i created the function. Before that I was able to fetch the data without any hassle.Please suggest what may not be working right with us.

  • @anujpatel6438
    @anujpatel6438 4 года назад

    saved my arse bro ty

  • @eddiekim7801
    @eddiekim7801 4 года назад +1

    how did you operate 2 py files at the same time?

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад

      I am using PyCharm. And since it's under a large "for loop" and "while loop", the two files can operate at the same time.

    • @meylaul5007
      @meylaul5007 3 года назад

      @@eMasterClassAcademy yeah but for Eddie: You should be careful about where you plot the data, provided from your for-loop and while-loop. Those also have to be 2 separate "locations". or if you want to write this stuff to a file, use different files to which you want to write. Writing to the same target file, you'd need to specify exactly when and what and where it should go and how your file format should be. This is tedious work and needs synchronous work between for-loop and while-loop with the help of true/false flags. In example, you only write the content that is provided from your for-loop functionality to the file, if the flag of the while-loop is set to false, then you set the for-loop flag to false, which triggers the while loop to go into "true"-mode and provided a specific functionality write something different in A NEW LINE AT LEAST with hints that the written content comes from the while-loop. then you set the flag in the while loop to flase, which inturn could trigger the for-loop. But those are very complex control flow mechanisms, that need careful implementation and knowledge of the code. I'd personally would look out for existing examples of such things on Github NOT ON StackOverflow. Because Githubb-Scripts more often than StackOverflow yield fullfledged implementations and not only snippets.

  • @rushikeshpatil7253
    @rushikeshpatil7253 3 года назад

    Can you please help me with options open interest data

  • @tsven3932
    @tsven3932 4 года назад

    is there a way of making it print info faster? thanks:3

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 года назад

      In the code, ani=animation.FuncAnimation(fig, animate, interval = 1000), you can try to reduce the 1000 to print it faster. But it seems that the data that you scrap is not fast enough to match the update.
      But you can try matching the time duration for data updating and plotting to make it printing faster and better.
      Thanks

  • @abengeorge3059
    @abengeorge3059 4 года назад

    Hi, I am using Jupyter Notebook to run the files, however, I am only getting a horizontal blue line being displayed on each subplot. I have the files opened separately on jupyter. What could possibly be the issue? The code seems correct

    • @abengeorge3059
      @abengeorge3059 4 года назад

      Part 1 of pulling the data and storing it in a csv is working, but I don't think it is reading it from csv, even though the code is the same

  • @jonatapaulino
    @jonatapaulino 3 года назад

    Very good your work. Could you please make the code available?

    • @meylaul5007
      @meylaul5007 3 года назад

      Why would you not code it, while watching a video? What do you expect to learn from just taking his code and using it for yourself instead of understanding it? DO you even know how to set up your computer so you can run it? I never get those comments saying "Give me the code." Blunt.

    • @jonatapaulino
      @jonatapaulino 3 года назад

      @@meylaul5007 Sorry, it wasn't my intention to use your code, I just wanted to train by looking. Thanks.

  • @mongcm4508
    @mongcm4508 4 года назад

    interesting

  • @weida6055
    @weida6055 3 года назад

    pip3 from beautifulsoup4 import BeautifulSoup and from bs4 import BeautifulSoup

  • @ЕкатеринаТрескова-ш5н

    cant lissten to that schoup thing. its S! soup blin! omg

  • @danielfuerguth
    @danielfuerguth 4 года назад

    Which IDE are using??

  • @TarunKumar-cw9lu
    @TarunKumar-cw9lu 3 года назад

    please share source code

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

    You made something simple very confusing.

  • @shekharkumar1902
    @shekharkumar1902 3 года назад

    This video is incomplete and when you would code it would not work.

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

    this web scrathing is not available for indian market. such as stockname.NS extension. RELIANCE.NS