【发布时间】:2020-01-16 03:16:43
【问题描述】:
我正在尝试获取 Instagram 上每张图片的帖子描述,但我只得到描述的一小部分。有人可以帮我获取整个图片帖子描述吗?
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
# ---------------- getting hrefs in posts ------------------ #
# Step 1
driver = webdriver.Chrome('/Users/jjcauton/Documents/python/chromedriver')
driver.get('https://www.instagram.com/addict_for_sneakers/')
hrefs = driver.find_elements_by_tag_name('a')
print(hrefs)
hrefs_elem = [elem.get_attribute('href') for elem in hrefs]
hrefs_elem = [href for href in hrefs_elem if '/p/' in href]
print(hrefs_elem)
for href in hrefs_elem:
driver.get(href)
page = requests.get(href)
soup = BeautifulSoup(page.content, 'lxml')
page_contents = soup.title
contents = page_contents.get_text()
print(contents)
结果是这样的:
Boricua Adicto A Tenis on Instagram: “???? Giveaway ???? Win a FREE pair of Adidas Yeezy 350 v2 "Yeshaya" (Winner Picks His or Her Size) by following the simple steps below. Here’s…”
Boricua Adicto A Tenis on Instagram: “1,2,3,4,5,6,7,8,9 or 10?
#Tecatodetenis”
Boricua Adicto A Tenis on Instagram: “The the future of sneakers trading is here ???? Make money by buying shares, then selling them for more than what you paid ???? Start with only…”
Boricua Adicto A Tenis on Instagram: “What’s your favorite AJ11?”
Boricua Adicto A Tenis on Instagram: “???? Giveaway ???? Win a FREE pair of Retro 1 Fearless by following the simple steps below. Here’s how you can win????: 1️⃣ Follow:…”
Boricua Adicto A Tenis on Instagram: “1,2,3,4,5,6,7,8,9 or 10?
#Tecatodetenis”
Boricua Adicto A Tenis on Instagram: “Choose One!”
Boricua Adicto A Tenis on Instagram: “????FREE????GIVEAWAY???? Win the ????️red 1️⃣1️⃣ for FREE by following these steps: Step 1️⃣. Follow them????: @_jsole_ @wallkicksofficial @pr_sneaks23…”
Boricua Adicto A Tenis on Instagram: “What’s your favorite retro 4?”
Boricua Adicto A Tenis on Instagram: “???? Giveaway ???? Win a FREE pair of Retro 1 Turbo Green by following the simple steps below. Here’s how you can win????: 1️⃣ Follow:…”
Boricua Adicto A Tenis on Instagram: “1,2,3,4,5,6,7,8,9 or 10?
#Tecatodetenis”
Boricua Adicto A Tenis on Instagram: “✨LAST CHANCE✨ ☁️CHOOSE YOUR FAVORITE SHOE☁️ ⠀ To Enter Simply: 1️⃣: Like This Picture 2️⃣: Follow @Luisanglcordova @Hypedseason…”
如您所见,它只提供了图片帖子描述的一小部分。我需要完整的描述。谢谢!
【问题讨论】:
-
您在网络浏览器中打开页面时是否看到完整的描述?在哪个地方?当您看到完整的描述时,您是否已登录?
标签: python html selenium web instagram