Yes you can do it.
But how much money can you possibly make, since you will profit by the amount of the dividend which you will receive, but you're at market risk since the price of the stock my drop below your purchase price - therefore you lost money on the trade. Also, the amount of your dividend received will be taxed ar ordinary income rate (or possibly higher), and if you do make money on the trade you pay tax in this gain.
And if you buy prior to X-Date you get the dividend, but you do not have to wait until record date to receive it, you can sell on or after X-date to keep the dividend.
You better have a considerable amount of investing capital since you must pay for all purchases before you sell the stock,. if you sell without making payment in full your account is restricted for 90 days or until payment is received AND you can not use the proceeds of the sale to cover the purchase
from the street