是否可以从instagram网址获取图片网址?

时间:2019-09-17 07:13:36

标签: python api instagram

1 个答案:

答案 0 :(得分:1)

感谢@Chris Doyle的帮助,我可以使用selenium给您一些帮助:

from selenium import webdriver

driver = webdriver.Chrome('chromedriver.exe')
driver.get('https://www.instagram.com/p/B2EtjT9hgvG/')
metas = driver.find_elements_by_tag_name('meta')
for elem in metas:
    if elem.get_attribute('property') == 'og:image':
        print(elem.get_attribute('content'))

或相应地带有requestsbs4

import requests
from bs4 import BeautifulSoup

result = requests.get("https://www.instagram.com/p/B2EtjT9hgvG/")
c = result.content
soup = BeautifulSoup(c)
metas = soup.find_all(attrs={"property": "og:image"})
print(metas[0].attrs['content'])
相关问题