Onaylı Üye
python selenium kullanarak instagramda bir sayfaya girip tüm postlarını sırayla beğenen bir kod yazmaya çalışıyorum instagram apı olsa çok daha iyi olurdu ama instagra apı verebilecek ve ya nasıl alabileceğimi anlatabilecek varsa çok memnun olurum neyse
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
driver.get('
sleep(3) #Wait for loading page.
username_input = driver.find_element(By.NAME, 'username')
username_input.send_keys('senin k.adın')
password_input = driver.find_element(By.NAME, 'password')
password_input.send_keys('senin şifren')
sleep(2)
login_button = driver.find_element(By.XPATH, '//button[@type="submit"]')
login_button.click()
sleep(5)
# Profil sayfasına gidin
driver.get('
# Sayfayı yükleyin ve biraz bekleyin
sleep(10)
def scrollAllWayDown():
#This function scroll down to see the footer element and wait for a couple second. If page scroll length has changed then scroll again because that mean there is other pictures.
global driver
footer = driver.find_element_by_tag_name('footer') #The footer element
last_height = driver.execute_script('return document.body.scrollHeight') #Before scroll down note scroll length
while True:
footer.location_once_scrolled_into_view #Scroll down to see footer
sleep(2) #Wait for internet
new_height = driver.execute_script('return document.body.scrollHeight') #Run javascript code again to check scroll length.
if new_height == last_height: #If scroll height hasnt changed then there is no more pictures.
print('sayfa bitti!!!')
break
else: #If it changed set the last height equal new height and repeat function.
last_height = new_height
scrollAllWayDown()
tumKutular = driver.find_elements_by_class_name('v1Nh3') #Every photo attribute has a parent div so first find divs
tumLinkler = []
for i in tumKutular:
tumLinkler.append(i.find_element_by_tag_name('a')) #And find attribute in divs
for i in tumLinkler:
i.click() #Click link and open photo
sleep(2)
begenbuton = driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[1]/span[1]/button')
begenbuton.click() #Click heart button
sleep(0.2)
cikis = driver.find_element_by_xpath('/html/body/div[4]/div[3]/button').click() #Click exit button
kaynak kodlarını başka yerlerden aldım hepsi bana ait değil yardımcı olabilecek varsa çok iyi olur aldığım çıktı:
DevTools listening on ws://127.0.0.1:60004/devtools/browser/35aa8b7c-a1fa-4061-8ab4-1f2123283355
[9524:8612:1230/153635.776:ERROR:device_event_log_impl.cc(215)] [15:36:35.779] Bluetooth: bluetooth_adapter_winrt.cc:1074 Getting Default Adapter failed.
Traceback (most recent call last):
File "c:\Users\mansi\OneDrive\Masaüstü\python_temelleri\denelütfen.py", line 38, in <module>
scrollAllWayDown()
File "c:\Users\mansi\OneDrive\Masaüstü\python_temelleri\denelütfen.py", line 26, in scrollAllWayDown
footer = driver.find_element_by_tag_name('footer') #The footer element
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_tag_name'
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
driver.get('
Bağlantıları görmek için lütfen
Giriş Yap
') #Go to instagram login page.sleep(3) #Wait for loading page.
username_input = driver.find_element(By.NAME, 'username')
username_input.send_keys('senin k.adın')
password_input = driver.find_element(By.NAME, 'password')
password_input.send_keys('senin şifren')
sleep(2)
login_button = driver.find_element(By.XPATH, '//button[@type="submit"]')
login_button.click()
sleep(5)
# Profil sayfasına gidin
driver.get('
Bağlantıları görmek için lütfen
Giriş Yap
sayfa/?hl=tr')# Sayfayı yükleyin ve biraz bekleyin
sleep(10)
def scrollAllWayDown():
#This function scroll down to see the footer element and wait for a couple second. If page scroll length has changed then scroll again because that mean there is other pictures.
global driver
footer = driver.find_element_by_tag_name('footer') #The footer element
last_height = driver.execute_script('return document.body.scrollHeight') #Before scroll down note scroll length
while True:
footer.location_once_scrolled_into_view #Scroll down to see footer
sleep(2) #Wait for internet
new_height = driver.execute_script('return document.body.scrollHeight') #Run javascript code again to check scroll length.
if new_height == last_height: #If scroll height hasnt changed then there is no more pictures.
print('sayfa bitti!!!')
break
else: #If it changed set the last height equal new height and repeat function.
last_height = new_height
scrollAllWayDown()
tumKutular = driver.find_elements_by_class_name('v1Nh3') #Every photo attribute has a parent div so first find divs
tumLinkler = []
for i in tumKutular:
tumLinkler.append(i.find_element_by_tag_name('a')) #And find attribute in divs
for i in tumLinkler:
i.click() #Click link and open photo
sleep(2)
begenbuton = driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/article/div[3]/section[1]/span[1]/button')
begenbuton.click() #Click heart button
sleep(0.2)
cikis = driver.find_element_by_xpath('/html/body/div[4]/div[3]/button').click() #Click exit button
kaynak kodlarını başka yerlerden aldım hepsi bana ait değil yardımcı olabilecek varsa çok iyi olur aldığım çıktı:
DevTools listening on ws://127.0.0.1:60004/devtools/browser/35aa8b7c-a1fa-4061-8ab4-1f2123283355
[9524:8612:1230/153635.776:ERROR:device_event_log_impl.cc(215)] [15:36:35.779] Bluetooth: bluetooth_adapter_winrt.cc:1074 Getting Default Adapter failed.
Traceback (most recent call last):
File "c:\Users\mansi\OneDrive\Masaüstü\python_temelleri\denelütfen.py", line 38, in <module>
scrollAllWayDown()
File "c:\Users\mansi\OneDrive\Masaüstü\python_temelleri\denelütfen.py", line 26, in scrollAllWayDown
footer = driver.find_element_by_tag_name('footer') #The footer element
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_tag_name'
Moderatörün son düzenlenenleri: