我在从网站的HTML中提取播放器ID时遇到了一些问题。我以前做过,没有问题,但是这个特定html的href有点不同,让我很难堪。下面是HTML的一部分和我编写的脚本,它在打印后为每一行返回{}。下面的ID是'lynnla02',在HTML中出现两次,所以提取任何一个版本都可以。任何帮助都将不胜感激。你知道吗
HTML格式:
<tr data-row="248">
<th scope="row" class="right " data-stat="ranker" csk="240">1</th>
<td class="left " data-append-csv="lynnla01" data-stat="player">
<a href="/players/l/lynnla01.shtml">Lance Lynn</a>
我的一个尝试:
ID = []
for tag in soup.select('a[href^=/players]'):
link = tag['href']
query = parse_qs(link)
ID.append(query)
print(ID)
使用内置的
使用正则表达式:
要打印您要求的特定字符串:
相关问题 更多 >
编程相关推荐