gpt4 book ai didi

python - 使用 Python 从网页上的特定点复制文本

转载 作者:行者123 更新时间:2023-11-30 23:25:59 25 4
gpt4 key购买 nike

假设我有一个网页,例如 this ,我怎样才能复制从 <root response="True"> 开始的文本?并结束于 </root>

如何在 Python 中做到这一点?

最佳答案

import xml.etree.ElementTree as et
import requests

URL = "http://www.omdbapi.com/?t=True%20Grit&r=XML"

def main():
pg = requests.get(URL).content
root = et.fromstring(pg)

for attr,value in root[0].items():
print("{:>10}: {}".format(attr, value))

if __name__=="__main__":
main()

结果

    poster: http://ia.media-imdb.com/images/M/MV5BMjIxNjAzODQ0N15BMl5BanBnXkFtZTcwODY2MjMyNA@@._V1_SX300.jpg
metascore: 80
director: Ethan Coen, Joel Coen
released: 22 Dec 2010
awards: Nominated for 10 Oscars. Another 30 wins & 85 nominations.
year: 2010
genre: Adventure, Drama, Western
imdbVotes: 184,711
plot: A tough U.S. Marshal helps a stubborn young woman track down her father's murderer.
rated: PG-13
language: English
title: True Grit
country: USA
writer: Joel Coen (screenplay), Ethan Coen (screenplay), Charles Portis (novel)
actors: Jeff Bridges, Hailee Steinfeld, Matt Damon, Josh Brolin
imdbID: tt1403865
runtime: 110 min
type: movie
imdbRating: 7.7

关于python - 使用 Python 从网页上的特定点复制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com