我有一个Instagram网址:
https://www.instagram.com/p/B2EtjT9hgvG/
其中的图片具有该网址:
如果我只有Instagram网址,是否可以使用API或其他方式获取图片网址? TY
答案 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'))
或相应地带有requests
和bs4
:
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'])