Can you buy stocks the day before the ex dividend date, keep until the record date, then sell the stock(cont.)?

then sell the stock a day later, then take that money from before and invest it into a company that is having it's ex dividend date tomorrow and keep that stock until its record date and just continue this process in a cycle to just keep getting companies dividends?
10 answers 10