'Why Selenium only crawls 50 Instagram photos?
I made an image crawler using instagram's tag search function with selenium. And added a scroll function. However, there was a problem that only a maximum of 50 images could be saved. So, if I check the list of posts after scrolling, the previous element is deleted and the index starts from 1 again. Is there any way to save more pictures? Is it because Instagram restricts it or my computer specs are bad?
SCROLL_PAUSE_TIME = 3
while True:
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
time.sleep(3)
posts = soup.select('.v1Nh3.kIKUG._bz0w')
time.sleep(5)
for v in range(1, len(posts)):
print("\n==== index ==== : ", v)
last_height = driver.execute_script('return document.body.scrollHeight')
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(SCROLL_PAUSE_TIME)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(SCROLL_PAUSE_TIME)
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
else:
last_height = new_height
continue
for index, post in enumerate(posts):
print('https://www.instagram.com/' + post.a['href'])
imgUrl = post.select_one('.KL4Bh').img['src']
with urlopen(imgUrl) as f:
with open('./22ss/' + plusUrl + str(index) + '.jpg', 'wb') as h:
image = f.read()
h.write(image)
print(imgUrl)
print()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


