TypeError: sequence item 0: expected str instance, int found (web scraping)
TypeError: sequence item 0: expected str instance, int found (web scraping)
我正在使用 selenium 登录 Twitter,email
和 next
在我 运行 代码时工作,但是 password
和 login
不工作。
我得到以下 error
:
Terminal
:
PS C:\Users\xxx\OneDrive - xxx\Folder\Chrome Webdriver> & C:/Users/xxx/Anaconda3/python.exe "c:/Users/xxx/OneDrive - xxx/Folder/Chrome Webdriver/Twitter
Bot.py
DevTools 监听 ws://127.0.0.1:61543/devtools/browser/a9adea8e-a2bf-4a83-87ed-c39fb5a8f5aa
[32364:30428:1014/130628.297:ERROR:chrome_browser_main_extra_parts_metrics.cc(228)] crbug.com/1216328:开始检查蓝牙可用性。没有报告到此结束请报告
[32364:30428:1014/130628.297:ERROR:chrome_browser_main_extra_parts_metrics.cc(231)] crbug。com/1216328:检查蓝牙可用性结束。
[32364:30428:1014/130628.298:ERROR:chrome_browser_main_extra_parts_metrics.cc(234)] crbug.com/1216328:开始检查默认浏览器状态。没有报告到此结束请报告
[32364:31252:1014/130628.301:ERROR:device_event_log_impl.cc(214)] [13:06:28.302] USB: usb_device_handle_win.cc:1048 无法从节点连接读取描述符:A连接到系统的设备无法正常工作。 (0x1F)
[32364:31252:1014/130628.302:ERROR:device_event_log_impl.cc(214)] [13:06:28.303] USB: usb_device_handle_win.cc:1048 无法从节点连接读取描述符:A连接到系统的设备无法正常工作。 (0x1F)
[32364:31252:1014/130628.302:ERROR:device_event_log_impl.cc(214)] [13:06:28.303] USB: usb_device_handle_win.cc:1048 无法从节点连接读取描述符:A连接到系统的设备无法正常工作。 (0x1F)
[32364:30428:1014/130628.336:ERROR:chrome_browser_main_extra_parts_metrics.cc(238)] crbug.com/1216328: 检查默认浏览器状态结束。
追溯(最近一次通话最后一次):
文件“c:/Users/xxx/OneDrive - xxx/Folder/Chrome Webdriver/TwitterBot.py”,第 35 行,在
driver.find_element_by_xpath(password_xpath).send_keys(密码)
文件“C:\Users\xxx\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py”,第 478 行,在 send_keys
{'text': "".join(keys_to_typing(值)),
TypeError
:
sequence item 0: expected str instance, int found PS
C:\Users\xxx\OneDrive - xxx\Folder\Chrome Webdriver>
[31296:25628:1014/130651.989:ERROR:gpu_init.cc(453)] 不支持直通,GL 已禁用,
角度是
[31488:15052:1014/130825.008:ERROR:gpu_init.cc(453)] 不支持直通,GL 已禁用,ANGLE 为
Code
:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
def account_info():
with open('account_info.txt', 'r') as f:
info = f.read().split()
email = info[0]
password = [1]
return email, password
email, password = account_info()
options = Options()
options.add_argument("start.maximized")
driver = webdriver.Chrome(options=options)
driver.get("https://twitter.com/i/flow/login")
time.sleep(1)
email_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[2]/label/div/div[2]/div/input'
next_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div'
password_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[2]/div/label/div/div[2]/div/input'
login_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div'
time.sleep(1)
driver.find_element_by_xpath(email_xpath).send_keys(email)
time.sleep(0.5)
driver.find_element_by_xpath(next_xpath).click()
time.sleep(0.5)
driver.find_element_by_xpath(password_xpath).send_keys(password)
time.sleep(0.5)
driver.find_element_by_xpath(login_xpath).click()
你这里有错字:
password = [1]
应该是:
def account_info():
with open('account_info.txt', 'r') as f:
info = f.read().split()
email = info[0]
password = info[1]
return email, password
我正在使用 selenium 登录 Twitter,email
和 next
在我 运行 代码时工作,但是 password
和 login
不工作。
我得到以下 error
:
Terminal
:
PS C:\Users\xxx\OneDrive - xxx\Folder\Chrome Webdriver> & C:/Users/xxx/Anaconda3/python.exe "c:/Users/xxx/OneDrive - xxx/Folder/Chrome Webdriver/Twitter Bot.py
DevTools 监听 ws://127.0.0.1:61543/devtools/browser/a9adea8e-a2bf-4a83-87ed-c39fb5a8f5aa
[32364:30428:1014/130628.297:ERROR:chrome_browser_main_extra_parts_metrics.cc(228)] crbug.com/1216328:开始检查蓝牙可用性。没有报告到此结束请报告
[32364:30428:1014/130628.297:ERROR:chrome_browser_main_extra_parts_metrics.cc(231)] crbug。com/1216328:检查蓝牙可用性结束。
[32364:30428:1014/130628.298:ERROR:chrome_browser_main_extra_parts_metrics.cc(234)] crbug.com/1216328:开始检查默认浏览器状态。没有报告到此结束请报告
[32364:31252:1014/130628.301:ERROR:device_event_log_impl.cc(214)] [13:06:28.302] USB: usb_device_handle_win.cc:1048 无法从节点连接读取描述符:A连接到系统的设备无法正常工作。 (0x1F)
[32364:31252:1014/130628.302:ERROR:device_event_log_impl.cc(214)] [13:06:28.303] USB: usb_device_handle_win.cc:1048 无法从节点连接读取描述符:A连接到系统的设备无法正常工作。 (0x1F)
[32364:31252:1014/130628.302:ERROR:device_event_log_impl.cc(214)] [13:06:28.303] USB: usb_device_handle_win.cc:1048 无法从节点连接读取描述符:A连接到系统的设备无法正常工作。 (0x1F)
[32364:30428:1014/130628.336:ERROR:chrome_browser_main_extra_parts_metrics.cc(238)] crbug.com/1216328: 检查默认浏览器状态结束。 追溯(最近一次通话最后一次):
文件“c:/Users/xxx/OneDrive - xxx/Folder/Chrome Webdriver/TwitterBot.py”,第 35 行,在 driver.find_element_by_xpath(password_xpath).send_keys(密码)
文件“C:\Users\xxx\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py”,第 478 行,在 send_keys {'text': "".join(keys_to_typing(值)),
TypeError
:
sequence item 0: expected str instance, int found PS C:\Users\xxx\OneDrive - xxx\Folder\Chrome Webdriver>
[31296:25628:1014/130651.989:ERROR:gpu_init.cc(453)] 不支持直通,GL 已禁用, 角度是
[31488:15052:1014/130825.008:ERROR:gpu_init.cc(453)] 不支持直通,GL 已禁用,ANGLE 为
Code
:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import time
def account_info():
with open('account_info.txt', 'r') as f:
info = f.read().split()
email = info[0]
password = [1]
return email, password
email, password = account_info()
options = Options()
options.add_argument("start.maximized")
driver = webdriver.Chrome(options=options)
driver.get("https://twitter.com/i/flow/login")
time.sleep(1)
email_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[2]/label/div/div[2]/div/input'
next_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div'
password_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[1]/div/div[2]/div/label/div/div[2]/div/input'
login_xpath = '//*[@id="layers"]/div[2]/div/div/div/div/div/div[2]/div[2]/div/div/div[2]/div[2]/div[2]/div/div'
time.sleep(1)
driver.find_element_by_xpath(email_xpath).send_keys(email)
time.sleep(0.5)
driver.find_element_by_xpath(next_xpath).click()
time.sleep(0.5)
driver.find_element_by_xpath(password_xpath).send_keys(password)
time.sleep(0.5)
driver.find_element_by_xpath(login_xpath).click()
你这里有错字:
password = [1]
应该是:
def account_info():
with open('account_info.txt', 'r') as f:
info = f.read().split()
email = info[0]
password = info[1]
return email, password