解析http返回中断的lin

2024-09-28 19:10:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试解析来自某个电报通道的图像,例如https://t.me/versusbattlerus,图像就在这个块上 “img class="tgme_page_photo_image" src="https://... " but every time method returns different and not working links, why this happens? I'am using python 3.6, urllib, beautifulsoup4

方法

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()

Tags: https图像imageimportimgmaindefhtml
1条回答
网友
1楼 · 发布于 2024-09-28 19:10:08

这个脚本对我有效,请为测试提供“断开”链接。你知道吗

如果有bug,请尝试简单的Linux Shell解决方案:

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

相关问题 更多 >