简体   繁体   English

使用 Python 和 Selenium 在 Instagram 上抓取喜欢帖子的帐户的名称,但只返回了 11 个名称

[英]Scraping the names of the accounts who liked a post on Instagram, using Python and Selenium, but only 11 names returned

I am trying to scrape the names of the accounts who liked a post on Instagram, using Selenium and Python.我正在尝试使用 Selenium 和 Python 在 Instagram 上抓取喜欢帖子的帐户的名称。

https://www.instagram.com/p/B57dJp3gIGw/ https://www.instagram.com/p/B57dJp3gIGw/

There was no error returned, and I successfully scraped, but only the top 11 names of those who liked the post returned, while 40 persons liked the post.没有返回错误,我爬取成功,但是只返回了喜欢该帖子的前11名,而40个人喜欢该帖子。 I am wondering what the reason is, and how I can fix it?我想知道是什么原因,我该如何解决?

liker_list = []
likers = driver.find_elements_by_class_name("qyrsm")

for n in likers:
    #scrape the name of the likers
    liker = n.find_element_by_class_name("_4EzTm").get_attribute("textContent")
    liker_list.append(liker)


print(liker_list)

Here is the result(the liker_list)这是结果(liker_list)

['rycmtn', 'asat0oo', 'misswanderwolf', 'renkuga0202', 'na_na972', 'natsu_5550', 'hachibayinternational_inc', 'mi.kyoung.jeon', 'crane42195', 'michi___kusa', 'ankhcarpediem']

Most likely the page needs to be scrolled down to view all likes and scrape them.很可能需要向下滚动页面才能查看所有喜欢并抓取它们。

The chunk to scroll infinetly is below, and you can add what you have to the inside of this loop to scrape the data while it scrolls.无限滚动的块在下面,您可以将您拥有的内容添加到此循环的内部,以在滚动时抓取数据。

def scroll():

SCROLL_PAUSE_TIME = 1

# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
    # Scroll down to bottom
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    # Wait to load page
    time.sleep(SCROLL_PAUSE_TIME)
    # Calculate new scroll height and compare with last scroll height
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height
scroll()

You will add your code after the time.sleep(SCROLL_PAUSE_TIME) line.您将在 time.sleep(SCROLL_PAUSE_TIME) 行之后添加您的代码。

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python 获取在 Instagram 上评论或喜欢帖子的用户列表 - Get list of users who commented or liked post on instagram with Python StaleElementReferenceException 当我尝试使用 Selenium 和 Python 单击 Instagram 帖子的“被某人和 n 个其他人喜欢”中的“n 个其他人”时 - StaleElementReferenceException when I try to click the "n others" in "Liked by someone and n others" of an Instagram post, using Selenium and Python 使用 selenium 和 python 抓取 Instagram 关注者页面 - Scraping Instagram followers page using selenium and python Instagram 抓取:如何使用 selenium Python 获取 Instagram 个人资料名称 - Instagram scraping: How to get the Instagram Profile Name using selenium Python 如何查看谁喜欢 Instagram 桌面网站上的视频帖子 - How to see who liked a video post on instagram's desktop website Selenium Python Instagram 在帖子中抓取所有图像不起作用 - Selenium Python Instagram Scraping All Images in a post not working 使用 selenium 和 python 抓取 Instagram 列表 - Scraping Instagram Lists with selenium and python 我正在尝试使用 selenium webdriver 从 instagram 中抓取名称? - i'm trying to scrape names from instagram using selenium webdriver? 用硒刮Instagram粉丝 - Scraping Instagram followers using selenium 单击使用Selenium Python的Instagram帖子 - Click on Instagram post using Selenium Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM