Last active
March 28, 2024 10:55
-
-
Save Andiology/322bdc14d949612f5ef2a523f860a96a to your computer and use it in GitHub Desktop.
Instagram post urls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from bs4 import BeautifulSoup as Soup | |
import time | |
# browser = webdriver.Chrome() | |
url = 'https://www.instagram.com/bbcnews/' | |
browser.get(url) # 前往該網址 | |
# 往下滑並取得新的貼文連結 | |
n_scroll = 5 | |
post_url = [] | |
for i in range(n_scroll): | |
scroll = 'window.scrollTo(0, document.body.scrollHeight);' | |
browser.execute_script(scroll) | |
html = browser.page_source | |
soup = Soup(html, 'lxml') | |
# 尋找所有的貼文連結 | |
for elem in soup.select('article div div div div a'): | |
# 如果新獲得的貼文連結不在列表裡,則加入 | |
if elem['href'] not in post_url: | |
post_url.append(elem['href']) | |
time.sleep(2) # 等待網頁加載 | |
# 總共加載的貼文連結數 | |
print("總共取得 " + str(len(post_url)) + " 篇貼文連結") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recently created a music profile for myself on Instagram, but I never thought that it would be so difficult with instagram followers. And I found out that there is a service that helps you acquire a fairly large number of new subscribers in a short time. Now my profile is really popular and in demand.