我正在尝试自动化this Instagram 链接。我需要滚动并滚动并获取所有链接。我正在尝试关注但不起作用。
def fetch_links_by_hashtag(hash_tag):
url = 'https://www.instagram.com/explore/tags/marketing/'
driver.get(url)
driver.implicitly_wait(20)
is_more = False
try:
elem_more = wait.until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Load more")))
elem_more.click()
is_more = True
except Exception as ex:
print(str(ex))
pop = driver.find_element_by_tag_name('footer')
#pop = driver.find_element_by_link_text('About us')
# pop = driver.find_element_by_class_name('_4gt3b')
if pop is not None:
for i in range(10):
print('Calling scrolling script')
# It scolls till end
driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', pop)
sleep(4)
html = pop.get_attribute('innerHTML')
print(html)
最佳答案
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
关于Python Selenium : Scrolling not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41758095/