from lxml import html import requests #page_link = raw_input("Enter attribute page address: ") page_link = "http://daddyleagues.com/xm16/player/5187236/attributes" page = requests.get(page_link) tree = html.fromstring(page.content) position = tree.xpath('//*[@id="player-bio"]/div[2]/p[1]/span[2]/text()') pos = str(position[0]) #print pos player_name = tree.xpath('//*[@id="player-bio"]/div[2]/p[1]/span[1]/text()') name = str(player_name[0]) #print name attribute = ['SPD', 'STR', 'AGI', 'ACC', 'JMP', 'AWR', 'Stamina', 'Injury', 'Toughness', 'Production ', 'CTH', 'TRK ', 'ELU', 'SFA', 'SPM', 'JKM', 'BCV', 'CAR', 'KPW', 'KAC', 'MCV', 'ZCV', 'PRS', 'CTH', 'SPC', 'CIT', 'RTR', 'RLS', 'KR', 'TKL', 'HPW', 'PUR', 'PRC', 'PBK', 'RBK', 'IBK', 'PWM', 'FNM', 'BKS', 'THP', 'SAC', 'THA', 'MAC', 'TOR', 'DAC', 'PAC'] #print attribute rating = tree.xpath('//span[@class="grade"]/text()') #print rating del attribute[6:11] del rating[6:11] top5rat = list() top5att = list() for n in range(5): slot = rating.index(max(rating)) top5att.append(attribute[slot]) top5rat.append(rating[slot]) del attribute[slot] del rating[slot] #print top5att #print top5rat line1 = str() line1 = line1 + pos + " [b][url=" + page_link + "]" + name + "[/url][/b]" print line1 line2 = str() for n in range(5): line2 = line2 + str(top5att[n]) + ": " + str(top5rat[n]) + " | " print line2
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question