Functions
- scraper.get_comments_from_video(video_id, calls)[source]
Return the comments metadata for a given video. This metadata includes for example the comments text and language. More information on how a comment metadata object looks like can be found in the chapter source. Caution: The comment count of a user includes the number of original comments as well as the number of comment replies (comments to comments). With this function, you can only collect original comments, thus the number of collected comments will be less than the comment count.
- Parameters:
video_id (str) – Provide a video id as strings, eg. “7417415534339280160”. The id of a video can be found in the link to this video.
calls (int) – The number of calls for the function. Each call will return approximately 50 comments (as long as there are still comments to collect).
- Returns:
A list of comment metadata objects (see source)
- Return type:
list
- scraper.get_followers_of_user(profile_name, driver, limit)[source]
Return the followers for a given user. Requires the execution of start_selenium and login to TikTok first. Caution: Sometimes, the follower count displayed on TikTok is higher than the actual number of followers shown on TikTok.
- Parameters:
profile_name (str) – Provide one username, eg. “selenagomez”. The name of a user can be found in the link to the users profile, (e.g. https://www.tiktok.com/@selenagomez).
driver (selenium.WebDriver) – The driver you have created with start_selenium() (or your own driver)
limit (int) – Limit the number of results. If the number of followers exceeds this value, the function will return the names of the top l followers (or a little bit more).
- Returns:
A list of follower links, eg. [”https://www.tiktok.com/@imranadil915”, “https://www.tiktok.com/@user161624720276”].
- Return type:
list
- scraper.get_followings_of_user(profile_name, driver, limit)[source]
Return the links to users following a given profile. Requires the execution of start_selenium and login to TikTok first. Caution: Sometimes, the following count displayed on TikTok is higher than the actual number of followers shown on TikTok. Caution: The list of followings is private for many users, thus collecting the followings might not reveal any results.
- Parameters:
profile_name (str) – Provide one username, eg. “selenagomez”. The name of a user can be found in the link to the users profile, (e.g. https://www.tiktok.com/@selenagomez).
driver (selenium.WebDriver) – The driver you have created with start_selenium() (or your own driver)
limit (int) – Limit the number of results. If the number of followings exceeds this value, the function will return the names of the top l followings (or a little bit more).
- Returns:
A list of following links, eg. [”https://www.tiktok.com/@imranadil915”, “https://www.tiktok.com/@user161624720276”].
- Return type:
list
- scraper.get_profile_details(profile_names)[source]
Return profile metadata for a given user. This metadata includes for example the users statistics and privacy settings. More information on how a profile metadata object looks like can be found in the chapter source.
- Parameters:
profilenames (List[str]) – Provide usernames in a list of strings, eg. [“selenagomez”, “zachking”]. The name of a user can be found in the link to the users profile, (e.g. https://www.tiktok.com/@selenagomez).
- Returns:
A list of profile metadata objects (see source)
- Return type:
list
- scraper.get_video_details(video_ids)[source]
Get the metadata of one or more videos. This metadata includes for example the video title and description. More information on how a video metadata object looks like can be found in the chapter source.
- Parameters:
videos (List[str]) – Provide video id(s) in a list of strings, eg. [“7417415534339280160”,”7423680782276758817”]. The id of a video can be found in the link to this video.
- Returns:
A list of video metadata objects (see source)
- Return type:
list
- scraper.get_videos_by_keyword(keyword, driver, limit)[source]
Perform a keyword-search and collect the ids of the videos of the search results.
Caution: The TikTok keyword search will show anything related to a keyword. If you search for the word “dog”, it will give you videos with dog in the title, the music title, the username and more.
Requires the execution of start_selenium and login to TikTok first.
- Parameters:
keyword (str) – You can either use a keyword (e.g. “dog” or “funny dog”) or a hashtag (e.g. “#dog”)
driver (selenium.WebDriver) – The driver you have created with start_selenium() (or your own driver)
limit (int) – Limit the number of results. If the number of search results exceeds this value, the function will return the ids of the top l videos (or a little bit more).
- Returns:
List of video links, e.g. [”https://www.tiktok.com/@alvathehotdog/ video/7389719882289483041”, “https://www.tiktok.com/@unilad/ video/7010775526902107398”]
- Return type:
list
- scraper.get_videos_by_user(profile_name, driver, limit)[source]
Collect the ids of the videos for a given profile. Requires the execution of start_selenium and login to TikTok first.
- Parameters:
profile_name (str) – Provide one username, eg. “selenagomez”. The name of a user can be found in the link to the users profile, (e.g. https://www.tiktok.com/@selenagomez).
driver (selenium.WebDriver) – The driver you have created with start_selenium() (or your own driver)
limit (int) – Limit the number of results. If the number of user videos exceeds this value, the function will return the ids of the top l videos (or a little bit more).
- Returns:
List of video links, e.g. [”https://www.tiktok.com/@alvathehotdog/ video/7389719882289483041”, “https://www.tiktok.com/@unilad/ video/7010775526902107398”]
- Return type:
list
- scraper.start_selenium()[source]
This function will start an automated browser and first open wikipedia, then TikTok. Wait until the TikTok page is fully loaded. Then, you can manually login to TikTok, and answer the questions you are asked by TikTok (e.g. solve a captcha or disable cookies when asked). Once you are finished and the Tiktok Newsfeed is fully visible, you can execute the next function, using this driver object.
Alternatively, if you want to use another browser, you can use your own function to create a driver object.
Caution: With this function, we try to simulate a normal Chrome browser, not a test browser (as TikTok sometimes prevents the login from test browsers). To make this work, the Chrome browser needs to be installed on your system. If this functions starts a browser in a test environment, check whether you have chrome installed.
- Returns:
A driver object. This can be inserted in each function requiring the driver.