Answer the question
In order to leave comments, you need to log in
How to correctly parse site data that is loaded dynamically using Selenium?
Hello! I set a goal
for myself : to write a program that would download videos all / selectively from any (search is carried out by login) tikitok account.
I divided this task into subtasks. And with one of the subtasks (and it is the most important) there was a problem. Unable to programmatically load site content . For example, I took a random popular account https://www.tiktok.com/@egorkreed . At first I tried to get an html page using the requests library in conjunction with bs4 . I realized that this method is not suitable. The page is generated dynamically. Decided to use the Selenium library . Subtask code:
import time
from selenium import webdriver
URL = 'https://www.tiktok.com/@egorkreed'
def get_html(url):
driver = webdriver.Chrome()
driver.get(url)
get_html(URL)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
Answer the question
In order to leave comments, you need to log in
With each message, the bot receives a user object that has an identifier - the 'id' field.
Blocks (containing video) are not loaded programmatically
<div class="jsx-1410658769 video-feed-item">
...
</div>
https://m.tiktok.com/share/item/list?secUid=MS4wLjABAAAAel1W8SHY_s5E-E8fS9SFwEGKTV4TqtP-GotZf737nudl9M5gm99Pk_8bp8A0UXS8&id=6568346904743116806&type=1&count=30&minCursor=0&maxCursor=0&shareUid=&lang=&_signature=N5.bMAAgEBaTTMphzSDYUTef2iAAGmv
R4ndolphC4rter wondering what tiktok does in the browser what selenium doesn't do -
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js');
});
Video link selected: https://www.tiktok.com/@egorkreed/video/678***************5
Video link selected: https://www.tiktok.com/@egorkreed/video/678***************7
Video link selected: https://www.tiktok.com/@egorkreed/video/678***************4
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question