def get_table_data(self): self.data = [] etree = self.tree.xpath( '//div[@data-type="league-table-container"]/div[@data-type="table"]/div[@data-type="table-row"]' ) for element in etree: name = sc.get_text(element.xpath('./div[@class="team"]/text()')) place = sc.get_text( element.xpath('.//span[@data-type="rank"]/text()')) played = sc.get_text( element.xpath('.//div[@data-type="played"]/text()')) wins = sc.get_text( element.xpath('.//div[@data-type="wins"]/text()')) draws = sc.get_text( element.xpath('./div[@data-type="draws"]/text()')) losses = sc.get_text( element.xpath('./div[@data-type="losses"]/text()')) scored = sc.get_text( element.xpath('./div[@data-type="goals-scored"]/text()')) received = sc.get_text( element.xpath('./div[@data-type="goals-received"]/text()')) difference = sc.get_text( element.xpath('./div[@data-type="goal-difference"]/text()')) points = sc.get_text( element.xpath('./div[@data-type="points"]/text()')) print(name, place, played, wins, draws, losses, scored, received, difference, points) self.data.append([ name, place, played, wins, draws, losses, scored, received, difference, points ]) sc.Database(('name', 'place', 'played', 'wins', 'draws', 'losses', 'scored', 'received', 'difference', 'points'), 'table.db').database(self.data)
def get_matches_data(self): self.data = [] mount = int( self.tree.xpath( 'count(//div[@data-type="container"]/div[@data-type="evt"])')) for i in range(1, mount + 1): element = self.tree.xpath( '//div[@data-type="container"]//div[@data-type="evt"][' + str(i) + ']')[0] date = sc.get_text( element.xpath( './/preceding::div[@class="right fs11"][1]/text()')) time = sc.get_text( element.xpath('.//div[@class="min "]/span/text()')) home_name = sc.get_text( element.xpath('.//div[@class="ply tright name"]/span/text()')) away_name = sc.get_text( element.xpath('.//div[@class="ply name"]/span/text()')) score_home = sc.get_text( element.xpath('.//span[@class="hom"]/text()')) score_away = sc.get_text( element.xpath('.//span[@class="awy"]/text()')) print(date, time, home_name, score_home, score_away, away_name) self.data.append( [date, time, home_name, score_home, away_name, score_away]) sc.Database(('data', 'time', 'home_name', 'score_home', 'away_name', 'score_away'), 'matches.db').database(self.data)
def get_data(self): for number in range(1, 17): self.source = requests.get(self.url + str(number) + '/') self.tree = lxml.html.fromstring(self.source.content) self.etree = self.tree.xpath( '//div[@id="departement-content"]/a[@class]') for element in self.etree: self.location = sc.get_text( element.xpath('./span[@class="ville"]/text()')) self.name = sc.get_text( element.xpath('./span[@class="nom"]/text()')) self.description = sc.get_text( element.xpath('./span[@class="intitule"]/text()')) self.data.append([self.location, self.name, self.description]) sc.Database(('location', 'name', 'description')).push_data(self.data)
def get_data(self): for number in range(1, 247): print(number) self.url = self.get_url(number) self.source = requests.get(self.url) self.etree = lxml.html.fromstring(self.source.content) self.tree = self.etree.xpath('//div[@id="listingsResults"]//tr[not(@id)]') for element in self.tree: self.job = sc.get_href(element.xpath('.//div[@class="listing-title"]/a[@href]')) self.location = sc.get_text(element.xpath('.//div[@class="left-side"]/span[1]/following-sibling::span[1]/text()')) self.posted = sc.get_text(element.xpath('.//div[@class="left-side"]/span[2]/following-sibling::span[2]/text()')) self.link = sc.get_href(element.xpath('.//div[@class="left-side"]/span[3]/following-sibling::span[3]/a[@href]')) self.company = sc.get_text(element.xpath('.//div[@class="left-side"]/span[3]/following-sibling::span[3]//text()')) self.data.append([self.job, self.location, self.posted, self.link, self.company]) sc.Database(('job', 'location', 'posted', 'link', 'company')).push_data(self.data)
def get_data(self): self.etree = self.tree.xpath( '//table[@class="table"]//tr[following-sibling::tr]') self.name = sc.get_text( self.tree.xpath( '//div[@class="row bottom-margin-1x"][1]/div[1]/h1/text()[4]')) for element in self.etree: self.date = sc.get_text(element.xpath('./td[1]/text()')) self.open = sc.get_text(element.xpath('./td[2]/text()')) self.high = sc.get_text(element.xpath('./td[3]/text()')) self.low = sc.get_text(element.xpath('./td[4]/text()')) self.close = sc.get_text(element.xpath('./td[5]/text()')) self.volume = sc.get_text(element.xpath('./td[6]/text()')) self.market_cap = sc.get_text(element.xpath('./td[7]/text()')) self.list = [ self.date, self.open, self.high, self.low, self.close, self.volume, self.market_cap ] self.data.append(self.list) sc.Database( ('date', 'open', 'high', 'low', 'close', 'volume', 'market_cap'), file_name=self.name + '.db').push_data(self.data)