å¹´è¼äººå·²ç¶ä¸ç¨Lineäºï¼IGæ¯æªä¾ç社交平å°
æè¿æååæäºæ é½ç¨IGç§è¨æï¼å çºæçLineä¸åå°ææåä¸æ¬¡ï¼IGååéå §å°±å復äºãå çºLineå·²ç¶è¢«ãå·¥ä½æµ·å¯ãæ·¹æ²ï¼æææ¯ç§äººçè天平å°ï¼å»å æ¥èååå·¥ä½ãæ´»å群çµã
å¹´è¼äººå¨IGçæéæ¥ä»¥ä¿±å¢ï¼åçä¹å å°éåå³éï¼ç´ç´è½å¾IGç¶çç²çµ²åãè½æå¹³å°åå¾éæ°ç´¯ç©ç²çµ²ï¼ææ¹æ³çãå ¶å¯¦å¨IGä¸æåãæ·ºè¦åãï¼
æ人æææå¿ï¼æå°±æåå»
éåæ·ºè¦åå¨åå¤æ´å æ顯ãå æ¤è¥è½å¤ ççå°å°åç¾çç §çææå¿ï¼å°±è½å¤ è®åççç²çµ²å大éæå ï¼å æ¤æåå°±å©ç¨Pythonçå¥ä»¶ï¼Seleniumï¼ä¾éå°èªåå°åç¾ææå¿çå¯äº¤ä»ææã
å¨éå§æåä¹åï¼å¿ é è¦èè®è éæä¸åé»å¥ï¼å°±æ¯ï¼
å¥åæFBãLineé£ä¸å¥ï¼æ¬å°IGä¾
å¹´è¼äººæéåºLineï¼å çºè¢«å·¥ä½å æ¥ï¼æéLineåªæ滿滿çå£åãå¹´è¼äººæéåºFBï¼å çºé½æ¯å»£åï¼çè³æ許å¤å°é廣åç社åãåå ©åå¹³å°çæè¨ï¼è®æåç¥éï¼å¹´è¼ä¸ä»£è¦çæ¯ãçæ´»ãããæ°å¥ãããå¨æ¨ãï¼å æ¤ä¸ååªæ¯æææ°çååæ¾ä¸å»ãå ¬åæ天åºè£¡å ¬ä¼çã
å¨ä½¿ç¨Seleniumä¹åï¼å¿ é å å好IGçå®ä½ï¼æ以ä¸å¹¾åå¿ è¦æ¢ä»¶ï¼é裡以ç¥åçè±ææå¸å¹³å°voice tubeçIGå®æ¹å¸³èçºä¾ï¼
- ä¸è´çé¢¨æ ¼æè 主é¡ï¼ æ´åç²çµ²åçç«é¢è¦æä¸è´æ§çé¢¨æ ¼ï¼ä¸æåæ¯åèæç §ç就貼ä¸å»ã
- æ確çæå°å¯è¡å¸å ´ï¼ 確å®èªå·±çåç¾ãè¬å¦ï¼æ³å¸è±æç人ãæ³æ»ææ©ä½åä¸æ³æ²æé²æ¥ç人ã
- 幫åç¾ççæ´»å åï¼ éæ¯æéè¦çãåç¾æç麼éæ±ï¼é¤äºè½å¹«åç¾è§£æ±ºåé¡ä»¥å¤ï¼æ´è½å¢å åç¾èåççé»æ¿æ§ãvoice tubeå°±æ¯æ好çä¾åãæ³è¦å¨æ»IGæ¾é¬æï¼éè½è®è±æé²æ¥ï¼éæ´ç許å¤é»å½±çåè¨ï¼æ´è²¼è¿çæ´»ã
éè½è®æ¶è²»è æ²æå£åçæçºè¿½è¹¤åçç²çµ²åï¼ä¹ææ¯è®ç²çµ²åé·é·ä¹ ä¹ çä¸äºæ³éã
ç¶ä¸åå°±ç·ï¼æè½éå§é²è¡ãæå¿å¤§æ¾éãï¼ç¶²è·¯è¡é·éç¶å³æçå¿«ï¼ä½è² é¢è©å¹å³å¾æ´å¿«ï¼å æ¤ä¸å®è¦æºå好ååºç¼ã
è¥æ¨æ¯Pythonçæ°æï¼å»ºè°å¯ä»¥ä¸è¼Anacondaä¾æ建ç°å¢ã以ä¸å ©åAnacondaçä»ç´¹ï¼
Windwos&Mac Pythonåå¸è çºä»éº¼é¸æAnacondaçºéç¼ç°å¢å¢? -å ¥éç³»å
Python å ¥éå¿ çï¼Windows æ¶äººæ建Anaconda Python å¸ç¿ç°å¢-å ¥éç³»å
æ´å實ä½åªéè¦ç¨å°Seleniumå¥ä»¶ï¼å æ¤è¥æ¯ä½¿ç¨Anacondaï¼å°±ç´æ¥å¨Anaconda promptä¸è¼¸å ¥ä»¥ä¸æ令ï¼è¥å¨ç³»çµ±ç°å¢ä¸å®è£pythonï¼åç´æ¥å¨Terminalè²¼ä¸æ令å³å¯ã
pip install selenium
é»æä¸è¼phantomjs phantomjsæ¯Seleniumçæ§å¶å¨ï¼çæ¼æ¯å°pythonç¨å¼ç¢¼è®ææ©å¨äººçå·¥å ·ãSeleniumä¹æ以è½ç¬å°è¨±å¤ç¬è²ç¬ä¸å°ç網ç«ï¼å°±æ¯å çºSeleniumæ¯æ¨¡ä»¿äººçè¡çºï¼ççæéä¸åç覽å¨ï¼ä¸åå³çµ±çç¬è²ï¼ç´æ¥è«æ±å°å ä¸ä¾è§£æãç¶ç¶éåææ缺é»Seleniumçå·è¡æçç¸å°å°±å·®å¾å¤ï¼ä½é¢å°IGé種ãåæ å¼ãç網ç«ï¼å¿ é è¦ç¨Seleniumæè½éçå°ã
ä¸å系統ï¼å示å¯è½æä¸å¤ªä¸æ¨£ï¼ä½ä¸å½±é¿åè½ï¼è®è ä¸å¿ é度æå¿ã
é»æä¸è¼chromedriver chromedriveræ¯å°é給ç¨å¼æ§å¶çç覽å¨ãå æ¤å¯¦ä½æï¼ç¨å¼æ幫æ¨éåä¸åchromeç覽å¨ï¼ä¸¦ä¸æç §ç¨å¼èªåææéï¼ç¶ç¶ä¹å¯ä»¥äººå·¥ä»å ¥æä½ãchromedriverå¿ é èæ¨ç®åçchromeçæ¬ç¸åï¼è¥æ¨ä¸ç¥éæ¨chromeççæ¬ï¼å¯ä»¥é»é裡æ¥çéä¸è¼ççæ¬ï¼ç¢ºå®å¾ï¼å³å¯é»ä¸æ¹é¸æä¸è¼æªæ¡ã
phantomjsèchromedriverä¸è¼å®æå¾ï¼é½å¿ é æ¾å°ä¸»ç¨å¼çè³æ夾ä¸ï¼å¦ä¸åå³ï¼ï¼è®Python確ä¿è½æå°éå ©åæªæ¡ãè¥ç³»çµ±çºlinuxï¼å¯è½ææ使ç¨chromedriverèphantomjsæªæ¡æ¬éåé¡ï¼å æ¤å¿ é è¦è¼¸å ¥ä»¥ä¸ä¾æéæ¬éï¼777çºå ¨éï¼è¥æ¯è¦ºå¾æå®å ¨çæ ®è å¯ä»¥èªè¡èª¿æ´ï¼ã
å¿ é è¼¸å ¥æ¨ç帳èå¯ç¢¼ï¼ä»¥æ¹ä¾¿èªåç»å ¥ãtagsåæ¯è¼¸å ¥æ³è¦å°åªåtagæè®ï¼å æ¤éäºtagé常è¦èåçææç¸éã
IGID = 'ä½ çIG帳è'
IGpassword = 'ä½ çIGå¯ç¢¼'
tags=['guitar','guitarcover','music','piano']
è¨å®è«æ±æéçè³è¨ï¼å æ¤å¯ä»¥å¨21è¡ï¼ä¿®æ¹æèªå·±çUser-Agentï¼ä½è¥ç¨å¼å¯ä»¥å·è¡ï¼åå°±ä¸éè¦ç¹å¥ä¿®æ¹ï¼å æ¤å¯ä»¥å å·è¡éå»ï¼è¥æåºç¾bugï¼ååä¾æª¢æ¥å³å¯ã
User-Agentæ¯å°å å¨å³éæï¼å¿ è¦çè³è¨ï¼å æ¤è£¡é¢å¯ä»¥çå°è©²ä½¿ç¨è çç覽å¨ãä½æ¥ç³»çµ±çè³è¨ãå¨ç¬è²çæåï¼æäºç¶²ç«æ檢æ¥User-Agentæ¯å¦æ£ç¢ºï¼ä½å¨IGä¸ä¸ç¨ã
# è¨å®åºæ¬åæ¸
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
#æ¤èå¿
é ææèªå·±é»è
¦çUser-Agent
desired_capabilities['phantomjs.page.customHeaders.User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'
# PhantomJS driver è·¯å¾ ä¼¼ä¹åªè½çµå°è·¯å¾
driver = webdriver.PhantomJS(executable_path = 'phantomjs', desired_capabilities=desired_capabilities)
å·è¡ä»¥ä¸ç¨å¼ç¢¼ï¼å°±æå½åºä¸å空ç½çchromeãç¨å¼ç¢¼ä¸æä¸è¡è¨»è§£ï¼è¥ç¨å¼å·²ç¶ç©©å®ï¼ä¸éè¦è·³åºchromeäºï¼å°±å°éä¸è¡ç註解æ¿æå³å¯ã
# éééç¥æé
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
# 以ä¸ä¸å註解æéï¼ç覽å¨å°±ä¸æéå
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--no-sandbox')
# chrome_options.add_argument('--disable-dev-shm-usage')
# éåç覽å¨
driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
driver.getå³å¯æ§å¶chromeå°ä»»ä½æ¨æ³è¦ç網åãéåé段ï¼æäºå¸³èæè¨å®å ©é段é©èï¼çè³æ¯ç¨FBç»å ¥ï¼éå¯è½æé æç»å ¥ç¡æ³èªååï¼å æ¤éå¡ä¹å¯ä»¥ç´æ¥ç¨æåçæ¹å¼è¼¸å ¥ã
####### éå§æä½ è¼¸å
¥å¸³èå¯ç¢¼ç»å
¥ å°IGé¦é #######
driver.get("https://www.instagram.com/")
time.sleep(1)
assert "Instagram" in driver.title
time.sleep(3)
driver.find_element_by_xpath('//*[@name="username"]').send_keys(IGID) #輸å
¥ç»å
¥å¸³è
time.sleep(1)
driver.find_element_by_xpath('//*[@name="password"]').send_keys(IGpassword) # 輸å
¥ç»å
¥å¯ç¢¼
time.sleep(3)
# ç»å
¥
driver.find_element_by_xpath('//*[@type="submit"]').click()
é裡å°éå§ä¾ç §æ¨æè¨å®çtagï¼é²å»æ¯å¼µç §çææå¿ãææå¿æ¯å¾ãææ°ãéå§æï¼èä¸æ¯ãæç±éãï¼å çºãæç±éãé常é½æ¯åçãç¶²ç´ ï¼ä»å並ä¸æ追蹤æ¨çåçã
56è¡çè¿´åï¼æ±ºå®æå¨éåtagæå¹¾å¼µç §çæå¿ãé裡é½ä»¥äºæ¸çæ¹å¼æ±ºå®ï¼ç®çå¨æ¼ç¡éç模仿ç人ï¼ä»¥é²è¾è¦ç¶ççåçï¼è¢«å°éã
####### éå§æä½ å°ä¸åçtagå»ç¼æ #######
for tag in tags:
driver.get("https://www.instagram.com/explore/tags/" + tag) #åæå°è©²tag
time.sleep(random.randint(2,5))
driver.find_elements_by_class_name('_9AhH0')[9].click() #é»é¸åç(é¸æææ°ç¼ç)
for i in range(random.randint(20,25)):
if i % 10 == 1:
time.sleep(random.randint(5,20))
# 檢æ¥ææ²ææéè®
if len(driver.find_elements_by_xpath('//*[@aria-label="Unlike"]')) != 0 or len(driver.find_elements_by_xpath('//*[@aria-label="æ¶åè®"]')) != 0:
print('æéäº')
else:
time.sleep(random.randint(1,3))
try:
driver.find_element_by_xpath('//*[@aria-label="è®"]').click()
except:
try:
driver.find_elements_by_xpath('//*[@aria-label="è®"]')[1].click()
except:
print('åçæ²è·åºä¾ï¼ç´æ¥ä¸ä¸é ')
driver.find_elements_by_class_name('coreSpriteRightPaginationArrow')[0].click()
time.sleep(random.randint(1,5))
print(tag +' æå®äº')
time.sleep(random.randint(7,15)) # æå®ä¸åtagç¨å¾®ä¼æ¯ä¸ä¸ï¼ç¡é模仿ç人
注æï¼
ç¶é實測ï¼IGä¸å¤©ææå¿çæ¸éï¼å¤§ç´æ¯400次ï¼è¥è¶ é該帳èæ被å°éä¸å¤©ä¸è½ææå¿ï¼è¥æå¤æ¬¡é樣çç´éï¼çè³æå°é3天ãä¸ææï¼ä»¥æ¤é¡æ¨ï¼å æ¤è«é©åº¦ç使ç¨selenium就好ï¼éé»éæ¯å¨æ¼åçæä¾çµ¦æ¶è²»è çå¹å¼ã
æ以èªå·±ç帳è實é©ï¼å°å人åä»çå½±çä¸å³ï¼ä¸¦å°ææé¢¨æ ¼ç¶éæ´çãæ¯ä¸å¤©ä½¿ç¨ä¸æ¬¡æ©å¨äººææå¿ï¼ä¸åæ大ç´å¢å 200ç²çµ²ãä½éä¸å ©å禮æï¼å°±æ許å¤äººé追蹤äºï¼å æ¤æ²ææçºçç¶çï¼éè¦æ¼«ç¡ç®ççæå ï¼ææä¹ä¸å¼µã
作者:楊超霆 行銷搬進大程式 創辦人