【问题标题】:Is possibile to get image url from instagram url?是否可以从 instagram url 获取图像 url?
【发布时间】:2019-09-17 07:13:36
【问题描述】:

【问题讨论】:

  • 是的,有可能,源代码中有网址。
  • 使用beautifulsoup之类的东西从HTML中提取img url
  • instagram 中的图片是动态加载的,所以比美汤要复杂一些。包含图像的 div 显示为空。您可以下载整个 .html 页面,然后在其中找到它。
  • instagram页面的源代码中没有提到的图片的URL
  • @KostasCharitidis <meta property="og:image" content="https://scontent-lht6-1.cdninstagram.com/vp/a8309e3792e8820387eeef4683b879cb/5DFA5900/t51.2885-15/e35/s1080x1080/67472591_2116886595084247_1444361079130496531_n.jpg?_nc_ht=scontent-lht6-1.cdninstagram.com&_nc_cat=107" />

标签: python api instagram


【解决方案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'])

【讨论】:

    猜你喜欢
    • 2016-01-04
    • 2012-05-19
    • 1970-01-01
    • 1970-01-01
    • 2012-04-29
    • 1970-01-01
    • 2015-01-29
    • 1970-01-01
    相关资源
    最近更新 更多