第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用 Python 和 Beautiful-soup 從 Instagram 抓取標(biāo)簽

如何使用 Python 和 Beautiful-soup 從 Instagram 抓取標(biāo)簽

慕蓋茨4494581 2022-12-06 16:39:39
我試圖為 Instagram 上的熱門(mén)標(biāo)簽找到相關(guān)標(biāo)簽,但在使用 BeautifulSoup 時(shí)卻一無(wú)所獲import requestsimport html5libimport csvfrom bs4 import BeautifulSoupdef list_of_tags(tags):    related_tags = []    tmp = []    #for el in tags:    url = "https://www.instagram.com/explore/tags/love/"    req = requests.get(url)    soup = BeautifulSoup(req.content, 'html5lib')    print(soup)    r_tag = soup.find('div', attrs = {'class' : 'WSpok'})我已經(jīng)在其他網(wǎng)站上使用類(lèi)似的代碼進(jìn)行了抓取,并且取得了成功。但是在 Instagram 上嘗試時(shí),我沒(méi)有得到任何 HTML 內(nèi)容我嘗試調(diào)用特定的 div,但沒(méi)有用。我還有其他使用 JSON 請(qǐng)求的方法,但我想知道如何改進(jìn)這個(gè)版本。提前致謝
查看完整描述

1 回答

?
慕桂英546537

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊

我終于用json做到了


import requests

import html5lib

import json

import time

import csv

from bs4 import BeautifulSoup


def list_of_tags(tags):

    related_tags = []

    for el in tags:

        url = "https://www.instagram.com/explore/tags/"+ el +"/?__a=1"

        req = requests.get(url)

        data = json.loads(req.text)

        edges = data['graphql']['hashtag']['edge_hashtag_to_related_tags']['edges']

        for item in edges:

            related_tags.append(item['node']['name'])

    print(related_tags)

它將為您提供與您要查找的標(biāo)簽相關(guān)的所有標(biāo)簽


希望對(duì)某人有幫助。


查看完整回答
反對(duì) 回復(fù) 2022-12-06
  • 1 回答
  • 0 關(guān)注
  • 130 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)