python - selenium 从 instagram 设置中抓取请求列表的问题
问题描述
我从 selenium 的 instagram 设置中抓取请求列表时遇到问题。这是我的代码:
from time import sleep
from selenium import webdriver
#user_info
user = 'xxx'
password = 'xxx'
#login
bot = webdriver.Firefox()
bot.get('https://instagram.com')
sleep(2)
username_input = bot.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input')
sleep(1)
username_input.send_keys(user)
sleep(1)
password_input = bot.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input')
sleep(1)
password_input.send_keys(password)
sleep(1)
bot.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[3]/button/div').click( ) 睡觉(3)
#try_to_scraping_requested_profile
bot.get('https://instagram.com/accounts/access_tool/current_follow_requests')
sleep(2)
viewmore = 0
while viewmore <4:
bot.find_element_by_xpath('/html/body/div[1]/div/div/section/main/div/article/main/button').click()
viewmore += 1
sleep(1)
#this_is_where_the_problem_happend
requestlist =[]
users = bot.find_elements_by_class_name('-utLF')
print(users.text) #this_line_will_return_nothing
for user in users :
requestlist.append(user.text)
#also_the_requestlist_will_be_empty
print(requestlist)
解决方案
既然你提到
print(users.text) #this_line_will_return_nothing
users
在你的情况下是list
in Python selenium
。你不能.text
就一个list
。
为此:
for user in users :
requestlist.append(user.text)
#also_the_requestlist_will_be_empty
print(requestlist)
我建议先打印列表的大小:-
print(len(users))
看看里面有没有东西。我认为它没有任何东西,所以尝试不同的定位器。
推荐阅读
- c++ - ESP8266WiFi.h:没有这样的文件或目录
- maui-blazor - 如何向 Blazor-Maui 应用程序提供字节或图像?
- r - 如何在R中按国家和年份查找最大值?
- javascript - 如何正确配置我的 Cloudflare Worker 以将我发送的对象保存在 Cloudflare 的 KV(存储)中?
- python - 错误时在python中记录相关的局部变量
- rust - 参考文献用法
- javascript - 仅更改动态输入字段中的一个特定值
- sql - 查找同一类别中给定类型中不存在的唯一 ID 的计数
- sql-server - Wix SQL Server 安装 - NT AUTHORITY\NETWORK SERVICE 和 BUILTIN\Administrators 的本地化名称
- java - 如何在方法中将 for 循环转换为 while 循环?