首页 > 解决方案 > 如何从 Instagram 上的个人资料转到最近的帖子

问题描述

因此,我正在尝试制作一个程序,该程序可以自动在用户的所有 instagram 帖子下使用 selenium 进行评论。

但是我尝试过的所有 XPath 都不要去他们最近的帖子,他们什么都不做!

我的代码:

import os
import time
from colorama import *
from selenium import webdriver as wd
from selenium.webdriver.chrome.options import Options
import time
from time import sleep
init()

def main(username, password, target):
    while True:
        options = Options()
        options.headless = False  # Chrome Headless
        options.add_experimental_option('excludeSwitches', ['enable-logging'])
        driver = wd.Chrome('chromedriver.exe', options=options)
 
        driver.get("https://www.instagram.com/accounts/login/?source=auth_switcher")
        driver.find_element_by_xpath('/html/body/div[2]/div/div/div/div[2]/button[1]').click()
        sleep(2)
        driver.find_element_by_xpath("/html/body/div[1]/section/main/div/article/div/div[1]/div/form/div/div[1]/div/label/input").send_keys(username)
        driver.find_element_by_xpath("/html/body/div[1]/section/main/div/article/div/div[1]/div/form/div/div[2]/div/label/input").send_keys(password)
        driver.find_element_by_xpath("/html/body/div[1]/section/main/div/article/div/div[1]/div/form/div/div[3]/button").click()
        time.sleep(4)
        driver.get("https://www.instagram.com/%s/" % target)
        sleep(3)
        print("Reporting")
        driver.find_element_by_xpath("/html/body/div[1]/section/main/div/div[3]/article/div[1]/div/div[1]/div[1]/a/div[1]/div[1]")


 
 
def info():
    os.system('cls')
    print(Fore.LIGHTGREEN_EX + logo + Fore.RESET)
    username = input(Fore.LIGHTBLUE_EX + 'Username: @' + Fore.LIGHTGREEN_EX)
    password = input(Fore.LIGHTBLUE_EX + 'Password: ' + Fore.LIGHTGREEN_EX)
    target = input(Fore.LIGHTBLUE_EX + 'Target: @' + Fore.LIGHTGREEN_EX)
    main(username, password, target)
 
 
print(Fore.LIGHTGREEN_EX + logo + Fore.RESET)
info()

我在这个网站上很新,请不要介意,但我是否做错了什么,我应该从他们的个人资料中做,还是我愚蠢?

标签: pythonseleniuminstagram

解决方案


尝试使用响应式设计模式。Windows 中的 CTRL-Shift-M。


推荐阅读