如何在instagram上查看个人资料的最新帖子

时间:2020-10-11 18:12:39

标签: python selenium instagram

因此,我正在尝试创建一个程序,该程序会自动在用户的所有instagram帖子下方添加硒。

但是所有尝试使用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()

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

首先,确保您的Chrome浏览器版本与Chrome驱动程序兼容。 其次,您将系统环境变量Path设置为chromedriver.exe

像这样;

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    if (argc != 3)
        return 1;

    int x = atoi(argv[2]);

    char *s = argv[1], *d = argv[1];

    while (*s)
    {
        if (x == 0)
        {
            --x;

            while (*s && *s != ';')
                ++s;

            if (*s)
                ++s;
            else
                break;
        }

        if (*s == ';')
            --x;

        *d++ = *s++;
    }

    if (*(d - 1) == ';')
        *(d - 1) = '\0';
    else
        *d = '\0';

    puts(argv[1]);

    return 0;
}

然后我运行这段代码;

C:\webdrivers

尝试用这段代码替换您的xpath。 (有时无法正常工作)

相关问题