2017-03-14 7 views
0

私はPythonで特定のユーザーがInstagramの投稿をすべて取得しようとしています。私のコードの下には:Pythonを使用したInstagramフィードの取得

import requests 
from bs4 import BeautifulSoup 


def get_images(user): 
    url = "https://www.instagram.com/" + str(user) 
    source_code = requests.get(url) 
    plain_text = source_code.text 
    soup = BeautifulSoup(plain_text) 
    for image in soup.findAll('img'): 
     href = image.get('src') 
     print(href) 

get_images('instagramuser') 

しかし、私はエラーを取得しています:

UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently. 

The code that caused this warning is on line 14 of the file C:/Users/Bedri/PycharmProjects/untitled1/main.py. To get rid of this warning, change code that looks like this: 

BeautifulSoup([your markup]) 

to this: BeautifulSoup([your markup], "html.parser") markup_type=markup_type)) 

だから私の質問は、私が間違って何をやっていますか?

答えて

0

パーサーをBeautifulSoupに渡す必要があります。これはエラーではなく、警告です。

soup = BeautifulSoup(plain_text, "html.parser") 
0
soup = BeautifulSoup(plain_text,'lxml') 

私は>lxmlの <の代わりに使用することをお勧めします>代わりにrequests.get使用のhtml.parser <

urlopen

ここにすべてのコードです1行

012 BS4インポートBeautifulSoupからurllibはインポート要求 から

def get_images(user): 

    soup = BeautifulSoup(request.urlopen("https://www.instagram.com/"+str(user)),'lxml') 
    for image in soup.findAll('img'): 
     href = image.get('src') 
     print(href) 
get_images('user') 
関連する問題