I do want to point out, though, that it's hard to get a free lunch, and you'll have to do some research in order for any sort of dividend capturing strategy (buying just before the ex-dividend date and selling on the ex-dividend date) to work out for you vs. a buy-and-hold strategy. Typically, the price of the stock at any given time already accounts for these dividends and dates. In other words, it is generally going to be the case that any given stock, throughout the ex-dividend date, will trade at X amount lower than it otherwise would've, where X is exactly the amount of the dividend.
At various times, it may appear that the ex-dividend date had some kind of effect on the price (other than the obvious effect of reducing the price by the amount of the dividend), or seemed to fail to cause the lowering of price one would normally expect (which might lead you to believe that there's a potential free lunch if you were to buy the day before the ex-dividend date and sell on the ex-dividend date next time around), but the thing you have to remember is that you don't know what would've happened had that stock been a non-dividend stock. It's not good enough to just look at the price of a stock at closing on the day before the ex-dividend date and compare it to various prices on the ex-dividend date, because stock prices change all the time for lots of different reasons that have nothing to do with dividends and dates. A dividend is best thought of as a chunk of the price which is taken off between the day before the ex-dividend date and the day of the ex-dividend date, and not like something that just comes from out of nowhere that you can collect for free if only you buy and sell at the right time.
The reason dividends are important to many investors who gravitate towards dividend stocks is not that they get a free lunch that way, but instead because the dividend says something about the business. Many people will tell you that a recent dividend decrease might indicate trouble, for example. Another reason some people who like dividends like them is that they like not having their entire investment along with its gains wrapped up in a stock where the only way to get it is to sell and incur a commission. Dividends for retirees can be very important for this reason.
Some will tell you that a dividend capture strategy (buying just before the ex-dividend date and selling on the ex-dividend date) tends to work out well in a bull market but not in a bear market, but there's no convincing evidence for either proposition as far as I can tell. In other words, I do not think that you would end up profiting any more from a dividend capturing strategy in a bull market than you would if the same stock gave no dividends and you bought and sold it on the same date.
However, if you work very hard at this, and research enough, you may find that there are some small opportunities to exploit in terms of dividend capturing, especially if you have a lot of money to invest. I am not an expert, but, for example, it could conceivably be the case that an abnormal number of people sell certain stocks or certain kinds of stocks on the day or days before the ex-dividend date to purposely AVOID collecting a dividend because of the different tax treatment given for dividends vs. capital gains/losses--if a lot of people would generally prefer to not get the dividend amount in dividend form and instead take what is presumably about the same amount of money except in terms of a capital gain/loss, then you might be able to exploit that sort of phenomenon by figuring out when it happens, which stocks it tends to happen with, and then buying those at the right time before the ex-dividend date and selling at the right time on or after.
With a small amount of money to invest, you're probably better off spending your time figuring out what companies to invest in, and possibly whether it's a good time to invest in companies at all, than you are trying to get a free lunch by buying various stocks the day before the ex-dividend date and hoping you can sell the next day and turn a profit. Generally-speaking, putting a whole lot of work in attempting to get a free lunch by capturing dividends is a fool's errand and a waste of valuable time.