如何在HTML代码上获得包含特定文本的行

问题描述 投票:0回答:1

我正在尝试在html代码上获得包含特定文本的行

例如在此网络中:

https://animeflv.net/anime/otome-game-no-hametsu-flag-shika-nai-akuyaku-reijou-ni-tensei-shiteshimatta

在其代码中说:

var episodes = [[8,54514],[7,54485],[6,54456],[5,54430],[4,54400],[3,54367],[2,54327],[1,54271]];

我想知道如何使用python代码获得确切的行。

提前感谢

python html web
1个回答
0
投票
import requests
url = 'https://animeflv.net/anime/otome-game-no-hametsu-flag-shika-nai-akuyaku-reijou-ni-tensei-shiteshimatta'
r = requests.get(url)
for line in r.text.splitlines():
    if 'var episodes =' in line:
        break

print(line)
© www.soinside.com 2019 - 2024. All rights reserved.