Home > Mobile >  TypeError: sequence item 0: expected str instance, int found (web scraping)
TypeError: sequence item 0: expected str instance, int found (web scraping)

Time:10-18

I am using selenium to login to Twitter, the email and next work when I run the code, but the password and login do not work.

I get the following 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 listening on 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: Checking Bluetooth availability started. Please report if there is no report that this ends.

[32364:30428:1014/130628.297:ERROR:chrome_browser_main_extra_parts_metrics.cc(231)] crbug.com/1216328: Checking Bluetooth availability ended.

[32364:30428:1014/130628.298:ERROR:chrome_browser_main_extra_parts_metrics.cc(234)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.

[32364:31252:1014/130628.301:ERROR:device_event_log_impl.cc(214)] [13:06:28.302] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

[32364:31252:1014/130628.302:ERROR:device_event_log_impl.cc(214)] [13:06:28.303] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

[32364:31252:1014/130628.302:ERROR:device_event_log_impl.cc(214)] [13:06:28.303] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

[32364:30428:1014/130628.336:ERROR:chrome_browser_main_extra_parts_metrics.cc(238)] crbug.com/1216328: Checking default browser status ended. Traceback (most recent call last):

File "c:/Users/xxx/OneDrive - xxx/Folder/Chrome Webdriver/TwitterBot.py", line 35, in driver.find_element_by_xpath(password_xpath).send_keys(password)

File "C:\Users\xxx\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 478, in send_keys {'text': "".join(keys_to_typing(value)),

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)] Passthrough is not supported, GL is disabled, ANGLE is

[31488:15052:1014/130825.008:ERROR:gpu_init.cc(453)] Passthrough is not supported, GL is disabled, ANGLE is

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()

CodePudding user response:

You have typo in here:

password = [1]

should be:

def account_info():
  with open('account_info.txt', 'r') as f:
    info = f.read().split()
    email = info[0]
    password = info[1]
    return email, password
  • Related