首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类似InstaPy的by标签

类似InstaPy的by标签
EN

Stack Overflow用户
提问于 2022-01-19 23:32:01
回答 1查看 928关注 0票数 3

我一直运行Instapy没有任何问题,其他功能,如取消跟踪,跟踪,看故事和卷轴都仍然有效。我的问题是喜欢标签。我得到的错误信息是

代码语言:javascript
复制
Traceback (most recent call last):
  File "/Users/em/PycharmProjects/instabot_1/test_1_likes.py", line 61, in <module>
    session.like_by_tags(random.sample(like_tag_list, 3),
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instapy/instapy.py", line 1977, in like_by_tags
    inappropriate, user_name, is_video, reason, scope = check_link(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instapy/like_util.py", line 618, in check_link
    media = post_page[0]["shortcode_media"]
KeyError: 0

我通过Firefox、Pycharm运行Instapy,并使用Mac。我是Python的新手。

这是我正在运行的代码..。

代码语言:javascript
复制
import random
from instapy import InstaPy
from instapy import smart_run
browser = r'C:\Program Files\Mozilla Firefox\firefox.exe'



# login credentials
insta_username = 'myaccountname'
insta_password = 'mypassword'

dont_likes = ['sex', 'nude', 'naked', 'beef', 'pork', 'seafood',
              'egg', 'chicken', 'cheese', 'sausage', 'lobster',
              'fisch', 'schwein', 'lamm', 'rind', 'kuh', 'meeresfrüchte',
              'schaf', 'ziege', 'hummer', 'yoghurt', 'joghurt', 'dairy',
              'meal', 'food', 'eat', 'pancake', 'cake', 'dessert',
              'protein', 'essen', 'mahl', 'breakfast', 'lunch',
              'dinner', 'turkey', 'truthahn', 'plate', 'bacon',
              'sushi', 'burger', 'salmon', 'shrimp', 'steak',
              'schnitzel', 'goat', 'oxtail', 'mayo', 'fur', 'leather',
              'cream', 'hunt', 'gun', 'shoot', 'slaughter', 'pussy',
              'breakfast', 'dinner', 'lunch']

#friends = ['list of friends I do not want to interact with']

like_tag_list = ['vegan', 'veganfoodshare', 'veganfood', 'whatveganseat',
                 'veganfoodie', 'veganism', 'govegan',
                 'veganism', 'vegansofig', 'veganfoodshare', 'veganfit',
                 'veggies']

# prevent posts that contain some plantbased meat from being skipped
ignore_list = ['vegan', 'veggie', 'plantbased']

accounts = ['accounts with similar content']

# get a session!
session = InstaPy(username=insta_username,
                  password=insta_password,
                  headless_browser=True)

with smart_run(session):
    # settings
    session.set_relationship_bounds(enabled=True,
                                    max_followers=15000)

    #session.set_dont_include(friends)
    session.set_dont_like(dont_likes)
    session.set_ignore_if_contains(ignore_list)

    session.set_user_interact(amount=2, randomize=True, percentage=60)
    session.set_do_follow(enabled=True, percentage=40)
    session.set_do_like(enabled=True, percentage=80)

    # activity
    session.like_by_tags(random.sample(like_tag_list, 3),
                         amount=random.randint(50, 100), interact=True)

    session.unfollow_users(amount=random.randint(75, 150),
                           InstapyFollowed=(True, "all"), style="FIFO",
                           unfollow_after=90 * 60 * 60, sleep_delay=501)

    
session.end()
EN

回答 1

Stack Overflow用户

发布于 2022-02-26 20:36:43

这个问题是由于Instagram在其源代码中所做的更改造成的。从619转到like_util.py (请参阅INSTAPY文件所在的系统)文件,并将代码的这一部分更改为下面给您的代码(如果您找不到代码的这一部分,则使用短语media = post_page[0]["shortcode_media "]搜索文件like_util.py)

代码语言:javascript
复制
     media = post_page ['items'] [0]
     is_video = media ["is_unified_video"]
     user_name = media ["user"] ["username"]
     image_text = media ["caption"] ["text"]
     owner_comments = ""

之后,您将遇到另一个错误Could not find followers' for ... Grabbed 0 usernames from....

修复这些错误(至少对我有效,请备份并测试自己):

文件:xpath_compile.py

第111-117行:

从…

代码语言:javascript
复制
xpath["get_given_user_followers"] = {"followers_link": "//ul/li[2]/a/span"}

xpath["get_given_user_following"] = {
    "all_following": "//a[contains(@href,'following')]/span",
    "topCount_elements": "//span[contains(@class,'g47SY')]",
    "following_link": '//a[@href="/{}/following/"]',
}

代码语言:javascript
复制
xpath["get_given_user_followers"] = {"followers_link": "//ul/li[2]/a/div/span"}

xpath["get_given_user_following"] = {
    "all_following": "//a[contains(@href,'following')]/div/span",
    "topCount_elements": "//span[contains(@class,'g47SY')]",
    "following_link": "//a[contains(@href,'following')]/@href",
}

行: 97-104

从…

代码语言:javascript
复制
xpath["get_following_status"] = {
    "follow_button_XP": "//button[text()='Following' or \
                                  text()='Requested' or \
                                  text()='Follow' or \
                                  text()='Follow Back' or \
                                  text()='Unblock' and not(ancestor::*/@role = 'presentation')]",
    "follow_span_XP_following": "//button/div/span[contains(@aria-label, 'Following')]",
}

代码语言:javascript
复制
xpath["get_following_status"] = {
    "follow_button_XP": "//button/div[text()='Following' or \
                                  text()='Requested' or \
                                  text()='Follow' or \
                                  text()='Follow Back' or \
                                  text()='Unblock' and not(ancestor::*/@role = 'presentation')]",
    "follow_span_XP_following": "//button/div/span[contains(@aria-label, 'Following')]",
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70779087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档