Introduction
Learn how to automate boring mundane tasks in your life with Python, Selenium and BeautifulSoup.
In this video I explain how you can come up with projects that can be great for your resume. In most cases, finding a problem in your life that you want to solve will suffice. I walk you through a pain point in my life, specifically downloading tiktok videos without watermark and uploading it to youtube.
Link to code (You need to change some fields in the code to get it to work)
github.com/codewithvincent1/tiktokVideoScraper/blob/main/scrape_video.py
🔥 Drop a comment to help the algorithm :)
👍 Subscribe to get notifications for the next video
👉 Bootcamp Full Series Playlist: www.youtube.com/playlist
-----------------
😎 Resources
-----------------
👯 TikTok
📸 Instagram
💬. Join the Discord
📜. FREE Resume Template
📕. FREE Note taking template
beacons.ai/codewithvincent
-----------------
👾 Important Videos
-----------------
My Computer Science experience: www.youtube.com/watch
The side project that got me interviews: www.youtube.com/watch
My Resume walkthrough: www.youtube.com/watch
Ace your technical interviews: www.youtube.com/watch
-----------------
🧑🏻💻 About Me
-----------------
I am a full time iOS engineer, with over 7 years of programming experience.
My goal is teach you the bare minimum necessary to break into tech ASAP.
Learn more about my programming journey
7 years of coding in 12 minutes: www.youtube.com/watch
I offer 1 on 1 mentorship as well, feel free to DM me on discord
#python #automation #learntocode #codewithvincent
Tags: python automation, automate the boring stuff with python, learn python, automate your life, learn python fast, python fundamentals, learn to code, coding projects, coding project ideas, python tutorial, desktop automation, coding tutorial, python 101, how to automate tasks for beginners
Video
Yo, what's up YouTube it's been a while since I made a tutorial, but it's great to be back recently, I've been getting a lot of questions about what projects should I build to get a job to be honest, there's.
No one project that will guarantee that you'll get a job.
How I like to look at it is that you should build something that you're able to talk about for at least 10 minutes during an interview.
For example, if you built a calculator app, do you think that you can talk about it for at least 10 minutes so I built this calculator app that can add numbers subtract numbers.
Multiply Etc, it's, super cool, um, yeah.
That's about it.
As you can see this calculated app wasn't that interesting I wasn't passionate about it and I couldn't really talk about it that much.
However, if you build something that can solve a real life problem that you're facing you'll be more inclined to talk more about it.
So for today's video, I want to talk about a problem that I've been facing recently, and how I was able to solve it with python automation remember folks, if you ever find yourself doing a manual task over and over there's, probably a way that you can automate it with code.
So without further Ado let's get into it.
So before we touch any code, we need to identify a problem that we want to solve with automation for those of you that don't know, I hope my girlfriend run, a tick, tock account for our cat.
Papaya.
You guys should follow papayohoe.cat on tick, tock.
Currently, if you want to be a content, creator, you have to spread yourself out and repost your content on multiple platforms.
So that way you can grow, we've been creating our own content on Tick Tock.
But we also want to grow our presence on YouTube shorts.
The problem is we have over 500 Tech, talk videos and ain't.
Nobody got time to manually do this now moving forward.
We need to identify the steps to solve the problem manually.
So first I would open up the tick, tock website, click, the share button copy, the link and use some third-party websites to download the video without a watermark, and then I would upload it to YouTube shorts.
Everything I'm doing here is totally fine, but it's, very tedious and cumbersome.
And it takes a lot of time.
So since I know, Python and I know how to code I can automate this and that's, what I'll be showing you guys today.
So before you watch this video, make sure you know some python so that you can follow along if you don't have any python experience, don't worry, I have a playlist over here, it's completely free and top by myself.
So check it out without further.
Ado let's, go loading time.
Alright, so first things first let's, open up, Papaya's, Tick, Tock page.
And also just a reminder that this is just an example so feel free to use any Tick Tock page that you want to automate downloading videos for to get the link to the video.
All we have to do is open the video and copy the address at the top.
This method requires a lot of clicking.
So instead, we should think like programmers every website, basically uses HTML in order to link a user to another page.
We have to use an a tag and provide an href with the URL that we want to link the user to so to access the HTML on the page.
All we have to do is right, click and click inspect.
And this opens the console tool so that we can inspect the HTML on the page.
And as you move your cursor around you'll, see that it will highlight each HTML element.
So for our case, we want to see the a tags for each of these videos.
And when I move my mouse here, I see that the stuff that I want is highlighted so let's expand this.
So click, the arrow to expand.
And now, as you can see, there are two divs.
The first one is for videos and liked.
And the second one is for all of the videos.
So now let's expand this and let's expand this one.
And here we go.
We got each individual video.
So now let's open the first one and let's, try to find the a tag I'm going to expand this expand this expand this.
And look at that, we found the a tag and I'm just going to click on it, just to make sure that it works.
And this looks like the correct link.
So let's close this.
So now that we confirmed that this works.
The next thing we need to do is find a way to get this HTML document.
So that way we can grab all the hrefs for each video.
So we can achieve this very easily by using python selenium and beautiful soup.
So now open a new file and give it a name and save it.
And inside here type from selenium import Webdriver.
And this will basically import the selenium Library, which basically allows you to write automation code that opens a web browser.
And then it can click stuff search stuff and Etc.
You can kind of think of this as a bot.
So cool next just type driver equals webdriver.chrome, which basically specifies the browser that we want to use.
So, in this case, we want to use Chrome next type driver.get and then open the parenthesis.
And inside here, open quotation marks and paste the link of the website that you want to get.
So in this case, we want to get the tick, tock website.
And next we want to add a delay to the code so that way it waits for the website to load.
So we can do time dot sleep and then open the parenthesis and put one for one second.
And in order to use time in Python, we have to import time so let's type import time.
Cool.
So now that we have loaded the web page, we want to parse the HTML inside it and a great library for this is beautiful soup.
So to use beautiful soup, all we have to do is import it.
So we have to type from bs4 import beautiful soup.
And now in our code, we can do soup equals beautiful soup and then open the parenthesis and type driver, Dot, Page, underscore source, which will give us the HTML Source from the page and now hit comma space and open the quotes.
And inside here, type html.parser to specify that we want to parse HTML cool now in the next line, just type print open the parenthesis and do soup Dot prettify and then open the parenthesis.
This line will let us test whether our code works and purify just makes the HTML look, pretty so that it's easy for us to read now, hit save and save this code somewhere on your computer.
And now open your terminal and vs code in the top.
You can click terminal and click new terminal.
And this will just open a terminal and to run this code, you can type the command Python and I'm using python3 so I'll type, three space and then type the the name of your file.
So for me, it's scrape, underscore video, dot, Pi, if you're not python on your computer, make sure to install it.
Installing python is out of the scope for this tutorial.
So I won't be covering that.
And if you run into errors related to missing dependencies, you can fix that very easily by typing pip.
And in my case since I'm, using python3 I have to put a 3 at the end, and then you can just do install and basically the name of the module.
So here you can type selenium.
And then we want to install beautiful soup, which is bs4 like this and then hit enter.
And this will basically install the libraries that we need to run this code once everything is set up feel free to run the code.
And as you can see, it opened a web browser, and then it loads the page.
And after one second, the page closes because the code finished executing.
And now, if you look inside my terminal I, basically got the HTML for the page cool.
So now we basically have this HTML within our python code.
And the cool thing about beautiful soup is that it's able to find elements within the HTML.
So for example, each video is within a div with a class called Tick, Tock, Dash, x6y Etc.
And they all have the same class name.
So basically with beautiful soup, we can specify that we only want divs with the name, Tick, Tock, Dash, x6y, Etc, and it will select all of them and return it back as a list.
And to make our lives easier.
We should try to get the div closest to the a tag and the div that contains the a tag is Tick, Tock, Dash, YZ, 6i, Etc and just be safe.
We should double check that all the other divs have the same naming so let's open the second video and open the first div and open this div and open this div as well.
And here we see the a tag.
And now, if we look at the class, we see Tick, Tock, Dash, yz6ijl, Etc, which basically matches the one at the top.
So this makes our lives very easy.
So now we can just look for the div with this class name.
So let's copy this.
And now let's go back to our code.
And now remove this line and type videos equals soup dot find underscore all and now open the parenthesis and open the quotation marks and type div.
And then add a comma and then space and then open this clinical brackets.
And now inside here, open the quotation marks and type class and then open the colon and I open the quotation marks and paste that class name and all we're doing here is we're saying we want to find all the divs with the class name, Tick, Tock, YZ, Etc and I'll do print and let's get the length of the videos.
So that way we know how many videos we got back and then next, we can just Loop through each video.
So we can do for video in videos and add a colon and go to the next line.
And now just type prints open the parenthesis and type video.
And now we can do Dot.
And then we can type a, which means it's getting the a tag within the div and then open the square brackets and then open the quotation marks and type href, which means we want to grab the href value from inside.
The 8 and now let's hit save.
And now go back to your terminal and let's run this command again, cool.
So it opens the page and then one second later it closes.
And now if you look at my terminal again, we basically got all the links of the videos inside the page.
And if you look closely, we only got 29 videos.
This doesn't really add up because technically we actually have around 500 videos.
So it looks like something's, not working properly.
So let's go back to this page.
So one interesting thing about this page is that as you scroll more videos, get loaded.
So this is going to be a problem for our code because we're only loading whatever we can see initially.
So if we want to see more videos, we have to tell selenium to scroll through the page until it reaches the bottom.
So that way we can get all of the videos.
Now that sounds super complicated and that's, where Google comes in.
We should use Google as a resource to help us find a way to achieve this.
So I came across this medium post by Quan Wei.
And this does exactly what we want to do here's, the code that basically handles scrolling all the way to the bottom of the page.
So we only care about this part of the code so let's copy it and let's go back to our code and let's paste this in the middle before we grab the page Source from the driver and I'm missing an S here.
So let's, add it back.
So basically, this code just runs a while loop that executes JavaScript code to scroll down.
And then we have a variable I to keep track of how many times we have scrolled.
And here we tell the program to sleep for scroll pause time, which is just one second.
And here we execute another JavaScript function, which basically grabs the new scroll height of the page.
And we basically compare the height of the screen multiplied by the number of times that we have scrolled.
And we check whether this value is greater than the current scroll height.
And if it's greater that basically just means that we've reached the end of the page cool.
So now let's hit save.
And now let's run our code again, hit enter.
And here it opens the browser and let's.
Watch some magic.
You see that it's scrolling by itself isn't that awesome.
And now I'll just speed up the video and let it scroll all the way to the bottom five minutes later.
And that took a while because we had a lot of videos.
But now look at our console, we actually have a lot of videos.
And when I scroll all the way to the top you're gonna see that we have 457 videos in total I, guess I was off by like 50, but still that's a lot of videos.
Cool now that we have all these links.
The next thing we need to do is just go to this website ssstick.io, which basically allows you to download Tick, Tock videos without a watermark so let's paste, the link to one of the videos.
And before we hit download right, click on the page and go to inspect and then go to the networks Tab and basically on this tab, it will record network activity.
So let me show you what that means so let's go back to the page and click download.
And if you look at the right you're going to see that three Network activities happened when we click the download button, and if you click response, you're gonna see that it returns HTML.
And if you look here, there's an a tag, and if I scroll to the right and you're going to see that this a tag is for this fun without Watermark.
So basically we only care about this href from this a tag.
And if you right click on this network activity, go to copy and then click copy as curl go to the site called curled converter.com.
And inside this text field just paste what we copied, and this will turn the curl command into python.
So now scroll to the bottom and click copy to clipboard.
And now let's go back to your code and let's, create a function and call it download video and open the parenthesis.
And here it can take a link as a parameter and open the colon and hit enter and now paste the code that we just copied.
And now let's move this import to the top of the file.
So delete this line and scroll to the top and let's paste it on line, four and let's fix the spacing and hit enter.
And now scroll down.
And now let's indent all the code that we just copied and now let's fix the spacing.
So basically all the code here just represents the data that gets sent over when we make the request to that website.
And if you scroll all the way to the bottom you're going to see that we make a request to post data to this link, and we pass in the parameters and the cookies headers and the data.
And if you look in the data field, you're going to see this ID, which has a link to the tick tock video.
So instead of hard coding, a link, let's, replace this with link, which is the parameter that we added to this function.
So now let's copy the function name.
And here instead of printing, this value let's just call our download video function.
And now let's go back to the bottom of the page.
And after we make this request we'll, get back a response.
And since the response is HTML, all we got to do is just use beautiful soup to parse the HTML data.
So now let's create a new variable called download soup, and this will equal beautiful soup open the parenthesis and type response.
And if we dot text, this will give us the HTML inside the response and put a comma and open the quotation marks and type HTML dot parser and then hit enter and like I mentioned before we only care about the first a tag.
So we can get that very easily.
So let's do download link equals download soup dot a square bracket href.
And now the last thing that we need to do is to download the file.
So we have to import another Library.
So let's scroll to the top.
And now in line, five just type from URL lib dot request import URL open and hit enter.
And basically we will use this library to allow us to download the raw data of the file.
So now let's go back to the bottom of the page.
And after the download link, let's, create a new variable called mp4 file equals URL open.
And then we can pass it the download link, and this will download the file as raw data.
And now all we have to do is save this file onto our computer.
So let's do with open and then open the parenthesis and let's use an F string here.
So F quotation marks and I want to put it in a folder called videos, slash and open this Google brackets and let's, put the ID of the video here.
And then we can do dot MP4, and then add a comma and open the quotation marks WB, which stands for writing in binary.
So we need this in order to write to a file and then type as output, and then put a colon and hit enter and now we're going to write a while loop.
So while true all we're going to do is data equals mp4 file dot read 4096.
So now let's get back to the code so hit enter and now type if data.
So basically, if we're able to read data, we want to write this data to the output file so do output dot right and then open the parenthesis and put data and then hit enter, and then add an else statement where basically if no data comes back that just means that we finish reading from the file.
So now we can add a break statement, which means that we're done with the wow.
So now hit save.
And before you run, the code, make sure you make a folder called videos in the folder where your script is located, because in the example here, I'm creating the video inside of folder called videos and I'm, giving it an ID.
And that just reminded me, I forgot to pass a ID parameter.
So let's scroll up.
And and here inside the download video, add a comma and put ID here.
And in here, let's just pass the index as the ID.
So now, if we want the index all we have to do is add index here and add a comma.
And here on the videos, we do enumerate and open the parenthesis and close the parenthesis.
And this will basically give us the index along with the video, and now let's hit save.
And now let's run our script cool.
So it opens the page, and now it Scrolls to the bottom.
And yeah, of course, I got an error live coding is just too hard.
So basically, the error is saying that download video is not defined so let's, look at my code and I'm.
Assuming the error is because I declared the function after it was called so that's, why the code can't find it.
So we can fix this very easily so let's copy this whole function and let's delete it.
And now scroll to the top of the video and let's paste it above everything else and hit save and let's try this again, oh crap looks like I got another error I just had a spelling mistake.
So I was supposed to capitalize this F.
So let me do that.
And let me try this again, all right, let's cross our fingers and hope that everything works.
Fine.
Ah, crap.
We got another error, hmm, it looks like our script wasn't able to read the href inside the a tag.
But on the bright side, it looks like we did download one video so let's open this video and make sure that it works.
Nice.
It looks like it works.
But technically we're supposed to download all the videos right? And the issue here is that we're spamming a server with a lot of requests very quickly.
So the server probably thinks that we're bought, and we can actually get around this very easily by just adding an arbitrary DeLay So.
Now, let's scroll down and go to where we called the download video.
So right here.
So after we download one video, Let's do time dot sleep and let's just sleep for 10 seconds just be safe.
So let's save this and let's run the code again.
Third, time's, the charm right crossing my fingers let's go and look at that.
We got zero and one and let's, wait another 10 seconds and you're gonna see the next video get downloaded and look the third video just came in.
So because there's a 10 second delay, it's gonna be a long while before we download all the videos, but basically look it's working.
And this is awesome.
And unfortunately, YouTube has a cap and I can't, upload more than 10 videos at a time.
So I, guess what we have right now is pretty good.
Anyways, that's it for this video, I hope that you guys learned something new I wanted to share my thought process of how I approach this problem.
And how I was able to come up with the solution as you can see, we only scratched the surface of automation.
There is so many things that you guys can do if you ever get stuck, try to read the documentation for beautiful soup and also selenium.
And if you guys are up for the challenge, try to build your own web scraper to grab some useful data.
Maybe you guys can even build a sneaker bot, or even some application that will notify you when an item that you want to buy goes on sale.
Anyways, the world is your oyster.
So try to build something cool.
And let me know what you guys built in the comments below.
Thank you.
Guys I'll.
See, you later.
FAQs
Is there a trick to save TikTok without watermark? ›
Remove Watermark From a TikTok Video Using Android
Here's how to remove the watermark using the Video Eraser app: Tap the Remove Watermark from Video option on the app's landing page. Find the video you'd like to edit in your gallery. Slide the selector box to the area with the watermark.
Tikrank is a TikTok downloader and Facebook downloader . It can be used to save some popular video platform videos. And you can download videos without watermarks in batches.
How do I import a TikTok video without watermark? ›- Find the video you want to download without the watermark from the TikTok app.
- Tap “Share”
- Select “Copy Link”
- Open the App.
- Paste the link you copied from TikTok.
- Save the video to your photos without the watermark.
- Open the Photos app, select the downloaded TikTok video, and tap Edit.
- Click the Crop icon and adjust the shape of the box to remove the TikTok watermark. ...
- After adjusting, click "Done" to save your video.
SnapTik is available to download for Android, or you can opt to access it through a browser. Simply paste the link of the video that you want to download and click on one of the Download server buttons. Allow enough time for your video to process; it will download on your phone without the watermark.
What website removes TikTok watermark? ›SnapTik is an online tool for downloading TikTok videos without watermark. All required is the link to the TikTok video, paste it on the site and let the tool do the video processing for you. Once you have downloaded the video without a watermark, you can save it on your computer system, mobile device, or tablet.
How do I remove TikTok watermark 2023? ›Here's how to remove TikTok watermarks with the same way by cropping on iOS and Android. Open Photos app, choose thedownloaded TikTok video, and tap on Edit. Tap on Crop icon and adjust the shape of that box to remove TikTok watermark.
Can I download all TikTok videos at once? ›You can find a bulk TikTok video downloader called EaseUS Video Downloader that downloads all your TikToks at once. With the TikTik downloader, you can not only download all TikTok videos from your and someone else's account on Windows and Mac, but also save sounds from TikTok.
What app can I use to download all TikTok videos at once? ›- Best TikTok Video Downloading Apps.
- Best TikTok Video Download App for Android & PC: Top Picks. 1) iTubeGo. 2) By Click Downloader. 3) 4KTokkit. 4) SnapDownloader. 5) YT Saver. 6) Snaptube. 7) YTD Video Downloader. 8) VidJuice UniTube. 9) VideoProc. 10) WinX Video Downloader.
Luckily, you can still get videos off the TikTok, even without the download option. By taking advantage of third-party TikTok video downloaders, you can save TikTok videos to PC or Mac without app.
How do I get rid of TikTok watermark on my iPhone? ›
Open Photos app on your iPhone, find and play the TikTok video that you need to remove the watermark, and tap on Edit. Tap on the Crop icon and adjust the shape of that box to remove TikTok watermark. Finally, tap on the Done to save the video without watermark.