机械化选择instagram表单

2024-09-30 18:22:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望使用Python Mechanize自动登录Instagramlogin,但是我得到一个错误"No form matching nr=0",这是我的代码。在

import mechanize

br = mechanize.Browser()
br.set_handle_robots(False)
response = br.open("http://www.instagram.com/accounts/login)
br.select_form(nr = 0)
br.form["username"] = "[my username]"
br.form["password"] = "[my password]"
br.method = "POST"
response = br.submit()

有人知道我怎么解决这个问题吗?表单没有名称,因此无法手动输入名称。在


Tags: no代码brform名称responsemy错误
1条回答
网友
1楼 · 发布于 2024-09-30 18:22:25
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.instagram.com/accounts/login/")

username = driver.find_element_by_xpath(
    '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[1]/input')
username.send_keys('my_username')

password = driver.find_element_by_xpath(
    '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[2]/input')
password.send_keys('my_password')
password.submit()

input('logged in...?')  # temporary so browser doesn't close immediately

driver.close()

相关问题 更多 >