import json import lxml import os import urllib from selenium.webdriver import ChromeOptions from bs4 import BeautifulSoup from selenium import webdriver import time from selenium.webdriver.chrome.service import Service # 获取抖音直播封面图片、链接、标题、主播名 if (os.path.isfile("test.txt")):
# os.remove() function to remove the file os.remove("test.txt")
# Printing the confirmation message of deletion print("File Deleted successfully") else: print("File does not exist")
html =browser.page_source soup = BeautifulSoup(html, 'lxml') # 生成BeautifulSoup对象
#hrefs =soup.find_all("a", class_="Jt6LO5RK o3pEYU7M") for each in soup.findAll("a", class_="Jt6LO5RK o3pEYU7M"): # get all elements with 'a' tag href = each.get('href') href2 = href.replace('https://live.douyin.com/', 'https://live.douyin.com/webcast/room/web/enter/?aid=6383&app_name=douyin_web&live_id=1&web_rid=') print(each) print(href2)