惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
B
Blog
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
爱范儿
爱范儿
博客园_首页
博客园 - 聂微东
量子位
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
The Cloudflare Blog
T
Tailwind CSS Blog
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC

博客园 - 你看起来真的很好吃

mac工具 linux系统时间管理 安装历史docker版本 OCR文本提取+NER命名实体识别 测试 深度学习-激活函数 go——make和new的区别 go——GC垃圾回收机制 go——标识符的命名规范 go语言——数据类型 go语言——转义符 go开发环境安装 git使用 项目文档目录总结 鼠标连点器——python版 windows使用YOLOV5训练模型——搭建编译环境 高匿名动态IP代理获取 logging模块进行格式化输出 Django admin 添加操作记录 facenet + fiass 实现人脸识别
笔记
你看起来真的很好吃 · 2023-09-23 · via 博客园 - 你看起来真的很好吃
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

class Tiktok:
def __init__(self):
# 创建浏览器实例
self.browser = webdriver.Chrome()
self.user_info = []

def get_fllow_info(self):
"""获取已关注主播信息"""
fllow_div = self.browser.find_element(By.XPATH, "//div[@id='main-content-homepage_follow']")
card_divs = fllow_div.find_elements(By.XPATH, "//div[@data-e2e='recommend-card']")

for index, item in enumerate(card_divs):
# 获取主播主页地址、姓名
index_url = item.find_element(By.XPATH, "a").get_attribute("href")
user_name = item.find_elements(By.XPATH, "//h3")[index].text
self.user_info.append({"name": user_name, "index_url": index_url})

def run(self):
# 打开网页
self.browser.get('https://www.tiktok.com/')

# 进入我的关注页面
element = WebDriverWait(self.browser, 120, 1).until(
EC.presence_of_element_located((By.XPATH, "//a[@data-e2e='nav-following']"))
)
element.click()

# 获取关注的主播信息
self.get_fllow_info()

# 查找搜索按钮并单击
search_button = browser.find_element_by_id('su')
search_button.click()

# 关闭浏览器
browser.quit()

if __name__ == "__main__":
tiktok = Tiktok()
tiktok.run()