Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to download full channel video profile XHS #205

Open
KalvinThien opened this issue Dec 9, 2024 · 1 comment
Open

how to download full channel video profile XHS #205

KalvinThien opened this issue Dec 9, 2024 · 1 comment

Comments

@KalvinThien
Copy link

i have optimized the automatic way to get user agent, and cookie with selenium, and used it to optimize the download, and it worked.

however i can't download all videos in 1 channel, can anyone help me, thank you
def get_browser_data():
"""Function to retrieve cookies and user-agent from the browser"""
try:
chrome_options = Options()
chrome_options.add_argument('--headless')

    driver = webdriver.Chrome(options=chrome_options)
    driver.get('https://www.xiaohongshu.com')
    
    # Retrieve cookies
    cookies = driver.get_cookies()
    cookie_string = "; ".join([f"{cookie['name']}={cookie['value']}" for cookie in cookies])
    
    # Retrieve user agent
    user_agent = driver.execute_script("return navigator.userAgent")
    
    driver.quit()
    print("Successfully retrieved cookies and user-agent")
    return cookie_string, user_agent
except Exception as e:
    print(f"Error while retrieving browser data: {e}")
    return None, None

async def app():
"""Run the application with automatically obtained cookies and user-agent"""
# Retrieve cookies and user-agent
cookie, user_agent = get_browser_data()

# Update the settings file
settings = Settings(ROOT)  # Create a new instance of Settings
current_settings = settings.run()  # Retrieve the current settings
current_settings.update({
    'cookie': cookie,
    'user_agent': user_agent
})
settings.update(current_settings)  # Update the settings file

# Initialize XHSDownloader
async with XHSDownloader() as xhs:
    await xhs.run_async()
@CallterC
Copy link

CallterC commented Jan 3, 2025

To my understanding, XHS doesn't send all the video information to the client's web browser upon visit, and you might need a way to mimic the mouse scroll movement to retrieve more video links. I am not sure if this is the problem you are facing, but that's my understanding on why you can't download all the videos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants