2017-10-18 116 views
1

我'試圖從一些電報信道解析圖像,如實施例https://t.me/versusbattlerus,該圖像是該塊上 「IMG類=」 tgme_page_photo_image」 SRC =‘HTTPS:// ...’,但每次方法返回不同的,而不是建立工作聯繫,爲什麼會這樣使用python 3.6,urllib的? 我',beautifulsoup4解析HTTP返回斷開鏈路

方法

import urllib.request 
from bs4 import BeautifulSoup 


def get_html(url): 
    response = urllib.request.urlopen(url) 
    return response.read() 


def parse(html): 
    soup = BeautifulSoup(html, 'lxml') 
    image = soup.find('img', class_="tgme_page_photo_image") 
    print(image) 
    #return image 


def main(): 
    parse(get_html('https://t.me/versusbattlerus')) 


if __name__ == '__main__': 
    main() 
+1

這正常工作與我 – chad

回答

0

此腳本適用於我,請提供「破」鏈接測試

如果有錯誤,嘗試簡單的Linux殼牌的解決方案:

curl -s https://t.me/SeanChannel |grep -oP '"og:image" content="\K.+(?=")' 
+0

對不起,你的意思是我的腳本爲你工作?所以你可以打開圖像嗎? –

+0

@ T3h_vermili0n是的,我可以打開它 – Sean