@@ -432,40 +432,37 @@ def from_content(cls, content):
432432 InvalidContent
433433 If the provided content is not the HTML content of the worlds section in Tibia.com
434434 """
435- parsed_content = parse_tibiacom_content (content , html_class = "TableContentAndRightShadow" )
435+ parsed_content = parse_tibiacom_content (content )
436436 world_overview = WorldOverview ()
437437 try :
438- record_row , * rows = parsed_content .find_all ("tr" )
439- m = record_regexp .search (record_row .text )
438+ record_table , worlds_header_table , worlds_table , * tournament_tables \
439+ = parsed_content .find_all ("table" , {"class" : "TableContent" })
440+ m = record_regexp .search (record_table .text )
440441 world_overview .record_count = parse_integer (m .group ("count" ))
441442 world_overview .record_date = parse_tibia_datetime (m .group ("date" ))
442- world_rows = rows
443- world_overview ._parse_worlds (world_rows )
443+ regular_world_rows = worlds_table .find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
444+ world_overview ._parse_worlds (regular_world_rows )
445+ if tournament_tables :
446+ tournament_world_rows = tournament_tables [1 ].find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
447+ world_overview ._parse_worlds (tournament_world_rows , True )
444448 return world_overview
445449 except (AttributeError , KeyError , ValueError ):
446450 raise InvalidContent ("content does not belong to the World Overview section in Tibia.com" )
447451
448- def _parse_worlds (self , world_rows ):
452+ def _parse_worlds (self , world_rows , tournament = False ):
449453 """Parses the world columns and adds the results to :py:attr:`worlds`.
450454
451455 Parameters
452456 ----------
453457 world_rows: :class:`list` of :class:`bs4.Tag`
454458 A list containing the rows of each world.
459+ tournament: :class:`bool`
460+ Whether these are tournament worlds or not.
455461 """
456- tournament = False
457462 for world_row in world_rows :
458463 cols = world_row .find_all ("td" )
459464 name = cols [0 ].text .strip ()
460465 status = "Online"
461- if len (cols ) == 1 and name == "Tournament Worlds" :
462- tournament = True
463- continue
464- elif len (cols ) == 1 and name == "Regular Worlds" :
465- tournament = False
466- continue
467- elif name == "World" :
468- continue
469466 online = parse_integer (cols [1 ].text .strip (), None )
470467 if online is None :
471468 online = 0
@@ -481,7 +478,6 @@ def _parse_worlds(self, world_rows):
481478 m = battleye_regexp .search (battleye_icon ["onmouseover" ])
482479 if m :
483480 world .battleye_date = parse_tibia_full_date (m .group (1 ))
484-
485481 additional_info = cols [5 ].text .strip ()
486482 world ._parse_additional_info (additional_info , tournament )
487483 self .worlds .append (world )
0 commit comments