您的位置:首页 > 娱乐 > 八卦 > 免费b站推广网站剧情_标准网站建设公司_十大免费b2b网站_seo资源是什么意思

免费b站推广网站剧情_标准网站建设公司_十大免费b2b网站_seo资源是什么意思

2024/10/5 6:21:57 来源:https://blog.csdn.net/sjc122333/article/details/142612481  浏览:    关键词:免费b站推广网站剧情_标准网站建设公司_十大免费b2b网站_seo资源是什么意思
免费b站推广网站剧情_标准网站建设公司_十大免费b2b网站_seo资源是什么意思

1、登录

  • 在页面中找到登录按键,使用selenium模拟点击
button_login = wd.find_element(By.XPATH,"//li[@id='J_SiteNavMytaobao']/div[@class='site-nav-menu-hd']/a[@target='_top']")button_login.click()

访问并寻找登录按钮

  • 找到用户名密码所在位置模拟输入
# 模拟输入账密button_username = wd.find_element(By.XPATH, "//div[@class='input-plain-wrap input-wrap-loginid ']/input")button_username.send_keys(zhangmi.username) # 替换为自己的用户名button_password = wd.find_element(By.XPATH, "//div[@class='input-plain-wrap input-wrap-password']/input")button_password.send_keys(zhangmi.password)# 替换为自己的密码

找到输入用户名密码的位置

  • 滑动进行验证,使用selenium模拟鼠标容易失败,所以我们在这里多等待一段时间手动滑动验证

滑动验证

2、搜索并找到数据

  • 找到搜索框输入所需要的物品,这里我们使用input动态输入

搜索按钮

  • 通过使用开发者工具找到商品所在位置,发现为由a标签组成
# 获取所有a标签
info = wd.find_elements(By.XPATH, "//div[@class='content--CUnfXXxv']/div/a")

商品链接

3、解析数据

  • 使用css选择器获取返回a标签包含的内容
# 商品标题messages_title = message.find_element(By.CSS_SELECTOR, ".title--F6pvp_RZ ").text# 商品特点messages_features = []messages_feature = message.find_elements(By.CSS_SELECTOR, ".text--eAiSCa_r")for k in messages_feature:messages_features.append(k.text)# 商品发货地messages_places = []messages_place = message.find_elements(By.CSS_SELECTOR, ".procity--QyzqB59i")for a in messages_place:messages_places.append(a.text)# 商品链接messages_url = message.get_attribute("href")# 商家信息messages_shop = message.find_element(By.CSS_SELECTOR, ".shopNameText--APRH8pWb").text

4、整理并储存数据

info = {"标题": messages_title,"特点": messages_features,"链接": messages_url,"商家信息": messages_shop,"商品发货地": messages_places}with open("./files/淘宝商品数据.txt", "a", encoding="utf-8") as f:f.write(str(info) + "\n")

相关代码链接:https://gitee.com/justinc666/crawler/blob/master/实战/4、爬取淘宝商品.py