[英]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.