【发布时间】:2022-01-16 08:05:29
【问题描述】:
@bot.event
async def on_message(message):
response = requests.get(f"https://steamid.io/lookup/" f"{on_message}")
steamid = BeautifulSoup(response.text, "html.parser")
print(steamid.prettify())
当我运行代码时,网站的代码写成html
<table class="table-striped table-hover">
<tr>
<td style="width:40%">
a steamID
</td>
<td>
<code>
STEAM_0:0:11101
</code>
</td>
</tr>
<tr>
<td>
a steamID3
</td>
<td>
<code>
[U:1:22202]
</code>
</td>
</tr>
<tr>
<td>
a steamID3 without brackets
</td>
<td>
<code>
U:1:22202
</code>
</td>
</tr>
<tr>
<td>
a steamID64
</td>
<td>
<code>
76561197960287930
</code>
</td>
</tr>
<tr>
<td>
a customURL
</td>
<td>
<code>
gabelogannewell
</code>
</td>
</tr>
<tr>
<td>
a full URL
</td>
<td>
<code>
http://steamcommunity.com/profiles/76561197960287930
</code>
</td>
</tr>
<tr>
<td>
a full URL with customURL
</td>
<td>
<code>
http://steamcommunity.com/id/gabelogannewell
</code>
</td>
</tr>
</table>
<p>
<br/>
Regular names as input may work and will yield a limited list of profiles, but only if the matching customURL is not taken. customURLs always prevail.
</p>
<p>
Trade URLs will
<i>
NOT
</i>
work.
</p>
<p>
To convert or look up multiple values, use the dropdown arrow to select
<i>
extended list
</i>
.
</p>
</div>
</section>
</div>
</div>
我想从这些代码中解析并选择以下部分
</tr>
<tr>
<td>
a steamID64
</td>
<td>
<code>
76561197960287930
</code>
</td>
</tr>
我想从这里解析并选择“76561197960287930”的部分,我该怎么做?
【问题讨论】:
-
嗨,欢迎来到堆栈溢出 :) 好吧,您要提取的数字在
<code>节点内。但是,您的 html 中有多个这样的节点,那么是什么让您要选择的部分与其他部分不同(例如,STEAM_0:0:11101)? -
我想要 steamID64 所有 steamID64 都以 765611 开头
-
我明白了。您能否提供一个完整的代码示例,我们可以运行该示例来重现您的输出。
-
请注意,当您执行实际查找时,生成的页面源是不同的。您展示的是查找值的示例。
-
你已经尝试了什么?
标签: python html beautifulsoup