Python Error IndexError: list index out of range -
import requests, sys bs4 import beautifulsoup r = requests.get("https://www.crossoutdb.com/"); s=beautifulsoup(r.content, 'lxml' ); it=s.find(id="itemtable").find("tbody"); f=open("market.csv", "w") f.write("item,faction,type,popularity,sell_price,sell_offers,buy_price,buy_ordes,margin\n") item in it.find_all("tr"): title=item.find(class_="item-title ").text.strip(); print(data); data=item.contents[1].text.strip().split("\n") title=data[0]; faction=data[1]; type=data[2]; rareity=item.contents[3].text.strip() popularity = item.contents[5].text.strip(); sell_price = item.contents[7].text.strip(); sell_offers = item.contents[9].text.strip(); buy_price = item.contents[11].text.strip(); buy_orders= item.contents[13].text.strip(); margin = item.contents[15].text.strip(); x="\"{}\",{},{},{},{},{},{},{},{}\n".format( title, faction, type,popularity, sell_price, sell_offers, buy_price, buy_orders, margin); f.write(x) f.close() error : traceback (most recent call last): file "**************\market_dumper.py", line 19, in faction=data[14]; indexerror: list index out of range
you having
error : traceback (most recent call last): file "**************\market_dumper.py", line 19, in faction=data[14]; indexerror: list index out of range
as data might not contain 15 elements. if did, line shouldn't throwing error. try print(data) , check if has 15 elements or not.
also, please edit post , put result of print() in post can see how many elements in data.
Comments
Post a Comment