提问人:Katerlad 提问时间:9/8/2022 最后编辑:Katerlad 更新时间:9/9/2022 访问量:155
C# Unity - 如何解析 Steam 新闻页面以提取 IMG URL?从 Get Resquest 收到的数据似乎不完整。是XHTML吗?
C# Unity - How To Parse a Steam News Page to Extract an IMG URL? The Data received from the Get Resquest seems incomplete. Is it XHTML?
问:
问题:
我在尝试解析此页面以查找包含图像链接的外壳 xml 标记时遇到问题。
https://store.steampowered.com/feeds/news/app/1348750/?cc=US&l=english&snr=1_2108_9__2107
我使用的是 Unity 和 C#,我以编码的 UTF-8 字符串或从 unitys UnityWebRequest.Get 方法的原始 byte[] 中获取数据。
当保存到文件或打印到文本框时,似乎很多数据都是混乱的。
我相信数据应该是 XHTML,我不确定如何将其转换为可读格式以开始解析 URL。
期望:
<item>
<title>Update v1.3</title>
<description>Changelog:<br><ul class="bb_ul"><li>Arry and Miri can now gain affection.<br></li><li>The player can now view Arry and Miri's epilogue scenes. (You will have to answer their proposal one more time.)<br></li><li>The Arry and Miri achievements have been fixed and should unlock when you reach the epilogue.<br></li><li>The ability management backend has been 100% REDONE, and all associated bugs should be fixed.<br></li><li>Specifically, ability use counts and levels will no longer reset if they're no longer in a player preset.</li></ul><br><div class="bb_h2">ACTION REQUIRED:</div>If you take one thing from this update, it's that <b>Arry and Miri's</b> conversation lines were <b>broken</b> before this update, with all their epilogue scenes being <b>hidden</b>. <br><br><b>If you've been stuck at their proposal, doing it one more time should unlock their achievements and lead you to their epilogue scenes.</b><br><br>Additionally, I've begun work on the logbook! It's coming along nicely.<br><br><img src="https://i.imgur.com/FBdDow9.png" /></description>
<link><![CDATA[https://store.steampowered.com/news/app/1348750/view/3178989079011859448]]></link>
<pubDate>Tue, 10 May 2022 02:28:06 +0000</pubDate>
<author>niku_treat</author>
<guid isPermaLink="true">https://store.steampowered.com/news/app/1348750/view/3178989079011859448</guid>
<enclosure url="https://cdn.akamai.steamstatic.com/steamcommunity/public/images/clans/38198503/25733639d563297f7a04c4fd68537f5b9aba3d67.png" length="0" type="image/png" />
</item>
实际:
这些只是数据中的片段,顶部是它能够显示的一些 HTML,底部看起来像 XML 部分或 XHTML?
<?xml version="1.0"?>
<string><!DOCTYPE html>
<html class=" responsive" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="theme-color" content="#171a21">
<title>Hearts of the Dungeon List - Steam News Hub</title>
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
ot;:&quot;Changelog:\n[list]\n[*]Arry and Miri can now gain affection.\n[*]The player can now view Arry and Miri's epilogue scenes. (You will have to answer their proposal one more time.)\n[*]The Arry and Miri achievements have been fixed and should unlock when you reach the epilogue.\n[*]The ability management backend has been 100% REDONE, and all associated bugs should be fixed.\n[*]Specifically, ability use counts and levels will no longer reset if they're no longer in a player preset.\n[\/list]\n\n[h2]ACTION REQUIRED:[\/h2]\nIf you take one thing from this update, it's that [b]Arry and Miri's[\/b] conversation lines were [b]broken[\/b] before this update, with all their epilogue scenes being [b]hidden[\/b]. \n\n[b]If you've been stuck at their proposal, doing it one more time should unlock their achievements and lead you to their epilogue scenes.[\/b]\n\nAdditionally, I've begun work on the logbook! It's coming along nicely.\n\n[img]https:\/\/i.imgur.com\/FBdDow9.png[\/img]&quot;,&quot;commentcount&quot;:1,&quot;tags&quot;:[&quot;mod_reviewed&quot;,&quot;ModAct_870845553_1652150701_0&quot;],&quot;language&quot;:0,&quot;hidden&quot;:0,&quot;forum_topic_id&quot;:&quot;3274690571081137373&quot;,&quot;event_gid&quot;:&quot;3178989079011859448&quot;,&quot;voteupcount&quot;:11,&quot;votedowncount&quot;:0,&quot;ban_check_result&quot;:0},&quot;published&quot;:1,&quot;hidden&quot;:0,&quot;rtime32_visibility_start&quot;:0,&quot;rtime32_visibility_end&quot;:0,&quot;broadcaster_accountid&quot;:0,&quot;follower_count&quot;:0,&quot;ignore_count&quot;:0,&quot;forum_topic_id&quot;:&quot;3274690571081137373&quot;,&quot;rtime32_last_modified&quot;:1653189104,&quot;news_post_gid&quot;:&quot;0&quot;,&quot;rtime_mod_reviewed&quot;:1652150697,&quot;featured_app_tagid&quot;:0,&quot;referenced_appids&quot;:[],&quot;build_id&quot;:0,&quot;build_branch&quot
示例代码
public static IEnumerator GetCoroutine(string url, Action<string> OnError, Action<string> OnSuccess)
{
using (UnityWebRequest result = UnityWebRequest.Get(url))
{
yield return result.SendWebRequest();
if (result.result == UnityWebRequest.Result.ConnectionError || result.result == UnityWebRequest.Result.ProtocolError)
{
OnError(result.error);
}
else
{
string rawUTF8Text = result.downloadHandler.text;
FileStream file;
string filePath = Application.persistentDataPath + "/xmlsave.xml";
file = File.Create(filePath);
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(file, rawUTF8Text);
file.Close();
OnSuccess(rawUTF8Text);
}
}
}
答: 暂无答案
评论