Firstly get a pig and a spider. Name the spider whatever u want ur pet to be called (Example: Fred) and then name the pig it with a _ (Example: Fred_). REMEMBER TO PUT A SADDLE ON THE PIG BEFORE U DO THE NEXT STAGE!
Then enter the command in a purple command block (Repeat) and type the command below (Example: /tp @e[name=Fred] @e[name=Fred_]) and put a redstone torch next to it!
Now you need to make the pig invisible do this by using the second command (Example: /effect @e[name=Fred_] minecraft:invisibility 10000 1 true) By putting true at the end it makes it so the pig wont have particles!
now just sit on that saddle you totally put on on the first stage (LIKE I ASKED IN CAPITAL LETTERS) and ride your spider!