Skip to content

Instantly share code, notes, and snippets.

View Andiology's full-sized avatar

Andiology Andiology

View GitHub Profile
# 往下滑並取得新的貼文連結
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')
# 尋找所有的貼文連結
# browser = webdriver.Chrome()
url = 'https://www.instagram.com/bbcnews/'
browser.get(url) # 前往該網址
from selenium import webdriver
from bs4 import BeautifulSoup as Soup
import time
@Andiology
Andiology / Instagram post urls.py
Last active March 28, 2024 10:55
Instagram post urls
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
@Andiology
Andiology / Instagram number of likes and comments 3.py
Last active September 10, 2020 02:46
Instagram number of likes and comments
post_url = '/p/CEriQnOMwW9/'
find = False
# 不在目前的網頁元素裡,則往下滑,加載新貼文
while not find:
try:
# 找到對應的貼文,鼠標移入
post_elem = browser.find_element_by_xpath('//a[@href="'+str(post_url)+'"]')
action = ActionChains(browser)
action.move_to_element(post_elem).perform()
# 找到需要的網頁元素
@Andiology
Andiology / Instagram number of likes and comments 2.py
Created September 8, 2020 13:20
Instagram number of likes and comments
# browser = webdriver.Chrome()
url = 'https://www.instagram.com/bbcnews/'
browser.get(url) # 前往該網址
@Andiology
Andiology / Instagram number of likes and comments 1.py
Created September 8, 2020 13:19
Instagram number of likes and comments
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
@Andiology
Andiology / Instagram number of likes and comments.py
Last active January 28, 2021 14:02
Instagram number of likes and comments
# 首先,以下是我們本次需要的套件,先import進來。
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
# browser = webdriver.Chrome()
url = 'https://www.instagram.com/bbcnews/'
browser.get(url) # 前往該網址
post_url = '/p/CEriQnOMwW9/'
find = False