Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从python上的html标记中获取特定文本?_Python - Fatal编程技术网

如何从python上的html标记中获取特定文本?

如何从python上的html标记中获取特定文本?,python,Python,我正在从一个API制作一个PythonMD5解密程序,但问题是API正在发回一个HTML反馈。如何获取之间的文本 {"error":0,"msg":"<font color=blue><b>Live</b></font><font color=green>Jumpman#23</font> | [MD5 Decrypt] .S/C0D3"} {“error”:0,msg:“LiveJumpman#23 |[MD5 Decr

我正在从一个API制作一个PythonMD5解密程序,但问题是API正在发回一个HTML反馈。如何获取
之间的文本

{"error":0,"msg":"<font color=blue><b>Live</b></font><font color=green>Jumpman#23</font> | [MD5 Decrypt] .S/C0D3"}
{“error”:0,msg:“LiveJumpman#23 |[MD5 Decrypt].S/C0D3”}

我建议将HTML解析器用作:


如果您知道目标文本正好是
,则可以使用简单的字符串操作:

msg = "<font color=blue><b>Live</b></font><font color=green>Jumpman#23</font> | [MD5 Decrypt] .S/C0D3"
start_pattern = "<font color=green>"
stop_pattern = "<"
start_index = msg.find(start_pattern) + len(start_pattern)
stop_index = start_index + msg[start_index:].find(stop_pattern)
print msg[start_index:stop_index]
msg=“LiveJumpman#23 |[MD5 Decrypt].S/C0D3”
start_pattern=“”

stop_pattern=“您可以使用
bs4
和相邻的同级组合符作为字体标记

from bs4 import BeautifulSoup as bs
s = {"error":0,"msg":"<font color=blue><b>Live</b></font><font color=green>Jumpman#23</font> | [MD5 Decrypt] .S/C0D3"}
soup = bs(s['msg'], 'lxml')
data =  soup.select_one('font + font').text
print(data)
从bs4导入美化组作为bs
s={“error”:0,msg:“LiveJumpman#23 |[MD5 Decrypt].s/C0D3”}
汤=bs(s['msg'],'lxml')
数据=汤。选择一个('font+font')。文本
打印(数据)

使用诸如bs4(BeatifulSoup)之类的HTML解析器,感谢answer@LimitedBrainCells,如果这有用,您介意验证答案吗?字体颜色重要吗?还是需要更广泛地应用于两者之间?
msg = "<font color=blue><b>Live</b></font><font color=green>Jumpman#23</font> | [MD5 Decrypt] .S/C0D3"
start_pattern = "<font color=green>"
stop_pattern = "<"
start_index = msg.find(start_pattern) + len(start_pattern)
stop_index = start_index + msg[start_index:].find(stop_pattern)
print msg[start_index:stop_index]
from bs4 import BeautifulSoup as bs
s = {"error":0,"msg":"<font color=blue><b>Live</b></font><font color=green>Jumpman#23</font> | [MD5 Decrypt] .S/C0D3"}
soup = bs(s['msg'], 'lxml')
data =  soup.select_one('font + font').text
print(data)