如何解决Python:UnicodeDecodeError:“utf-8”编解码器无法解码位置 146 中的字节 0xbe:起始字节无效
运行后
pyinstaller --onefile -w main.py
我明白
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 146: invalid start byte
不知道为什么,这是我的代码
def getGameInfo(x):
a1 = x.a(class_="search-results-row-price")[0].text
return {"name": x.a(class_="search-results-row-game-title")[0].text,"price": " ".join(a1.split()),"link": x.a['href']}
console = Console()
table = Table(show_header=True,Box=rich.Box.MINIMAL)
table.add_column(header="#",min_width=1)
table.add_column(header="Title",header_style="Bold Red",style="Red")
table.add_column(
header="Price",header_style="Bold Yellow",style="Yellow")
table.add_column(header="Link",no_wrap=True,header_style="Bold Blue",style="Blue")
console.clear()
ft = input("game title: ").replace(" ","+")
txt = requests.get(
f"https://www.allkeyshop.com/blog/catalogue/search-{ft}/")
soup = bs4.BeautifulSoup(txt.text,'html.parser')
found = soup.find_all("li",class_="search-results-row")
if len(found) == 0:
console.print(
"\n[bold red]There isn't any game listed under that name on AKS.[/bold red]")
sys.exit()
for x in range(0,max_entries):
info = getGameInfo(found[x])
table.add_row(str(x+1),info['name'],info['price'],info['link'])
table.add_row()
print()
console.print(table)
console.print("created by:\nhttps://github.com/Natqo")
我尝试使用其他编译器并更改文件的编码,但仍然没有运气 还尝试了 .encode('utf-8') 文件中的大部分字符串
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。