我正在尝试创建一个跟踪器程序,并使用BeautifulSoup和requests库来降低Steam网站的价格。然后使用openpyxl将这些价格值写入excel文件。在
在前四场比赛中,一切都完美无瑕。当游戏中存在更多的标题时,我尝试添加更多的错误。在
参见下面的代码
在我将空心骑士物品添加到wistlist数组后,我开始得到以下错误:
TypeError:“str”和“int”的实例之间不支持“<;”
即使我没有用任何比较符号来比较这个程序中的值。在
旁注: 我有一个json文件,它存储了将值放入excel的下一行。程序在执行完上面的所有代码后,会将行值更新1。请参见下面的函数updateTrackingLines()
cookies = {'birthtime': '568022401'} # For Steam's age verification
wishlist = [
"https://store.steampowered.com/app/477160/Human_Fall_Flat/",
"https://store.steampowered.com/app/242760/The_Forest/",
"https://store.steampowered.com/app/4000/Garrys_Mod/",
"https://store.steampowered.com/app/271590/Grand_Theft_Auto_V/",
"https://store.steampowered.com/app/367520/Hollow_Knight/",
"https://store.steampowered.com/app/588650/Dead_Cells/s",
"https://store.steampowered.com/app/320240/We_Happy_Few/", "https://store.steampowered.com/app/589510/Shovel_Knight_Specter_of_Torment/",
"https://store.steampowered.com/app/413150/Stardew_Valley/"
]
l = len(wishlist)
def updateProducts():
wb = openpyxl.load_workbook("C:\Python37\SteamTracker\ProductsTracker.xlsx")
sheets = wb.get_sheet_names()
today = date.today()
today = today.strftime("%m/%d/%Y")
lines = getTrackingLines()
for i in range(0,l):
sheet = wb.get_sheet_by_name(sheets[i])
html = requests.get(wishlist[i],cookies=cookies)
page_soup = soup(html.content, "html.parser")
price = page_soup.find("div",{"class":"game_purchase_price price"}).text.strip()
price = price[1:len(price)]
sheet.cell(lines[i],2, value = float(price)) # updating cells
sheet.cell(lines[i],1, value = today)
print("successed updating " + sheet.title)
wb.save("C:\Python37\SteamTracker\ProductsTracker.xlsx")
updateTrackingLines() # See explaination of this func above
完全回溯
^{pr2}$
问题解决了!在
看起来我用json文件在这里犯了一个小错误。在
当我在json中添加额外的项时,我意外地将值行编码为str-type而不是纯int
我们需要一个int值来定位excel表中的单元格,但是我的代码值行是str类型的。在
我最好学会小心打字。在
感谢您的帮助和参与这个主题
如错误所述,}。在
<
用于比较str
和{从代码行开始
^{pr2}$似乎您传递了}。在查看代码时,
str
为row
或{lines[i]
可能就是str
。在相关问题 更多 >
编程相关推荐