本文整理汇总了Python中utils.CanadianLegislator类的典型用法代码示例。如果您正苦于以下问题:Python CanadianLegislator类的具体用法?Python CanadianLegislator怎么用?Python CanadianLegislator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CanadianLegislator类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_people
def get_people(self):
page = lxmlize(COUNCIL_PAGE, 'iso-8859-1')
general_contacts = page.xpath('//p[@class="large_title"]/following-sibling::p/text()')
general_phone = general_contacts[0]
general_fax = general_contacts[1]
councillors = page.xpath('//tr/td/p/strong')
councillors = [councillor for councillor in councillors if not "@" in councillor.text_content()]
for councillor in councillors:
if 'Mayor' in councillor.text_content():
name = councillor.text_content().replace('Mayor', '')
district = 'Dollard-Des Ormeaux'
role = 'Maire'
else:
name = re.split(r'[0-9]', councillor.text_content())[1]
district = 'District ' + re.findall(r'[0-9]', councillor.text_content())[0]
role = 'Conseiller'
p = Legislator(name=name, post_id=district, role=role)
p.add_source(COUNCIL_PAGE)
p.image = councillor.xpath('./parent::p/parent::td/parent::tr/preceding-sibling::tr//img/@src')[0]
email = councillor.xpath('./parent::p/following-sibling::p//a[contains(@href, "mailto:")]')
if email:
p.add_contact('email', email[0].text_content(), None)
p.add_contact('voice', general_phone, 'legislature')
p.add_contact('fax', general_fax, 'legislature')
yield p
示例2: get_people
def get_people(self):
page = lxmlize(COUNCIL_PAGE)
councillors = page.xpath('//div[@id="WebPartWPQ1"]/table/tbody/tr[1]')
for councillor in councillors:
node = councillor.xpath(".//td[1]//strong//strong//strong//strong") or councillor.xpath(".//td[1]//strong")
text = node[0].text_content()
name = text.strip().replace("Deputy ", "").replace("Warden ", "").replace("Mayor", "")
role = text.replace(name, "").strip()
if not role:
role = "Councillor"
if "," in name:
name = name.split(",")[0].strip()
district = councillor.xpath('.//td[1]//p[contains(text(),",")]/text()')[0].split(",")[1].strip()
district = re.sub(r"\A(?:City|Municipality|Town|Township|Village) of\b| Township\Z", "", district)
p = Legislator(name=name, post_id=district, role=role)
p.add_source(COUNCIL_PAGE)
p.image = councillor.xpath(".//td[1]//img/@src")[0]
info = councillor.xpath(".//td[2]")[0].text_content()
residential_info = re.findall(r"(?<=Residence:)(.*)(?=Municipal Office:)", info, flags=re.DOTALL)[0]
self.get_contacts(residential_info, "residence", p)
municipal_info = re.findall(r"(?<=Municipal Office:)(.*)", info, flags=re.DOTALL)[0]
self.get_contacts(municipal_info, "legislature", p)
yield p
示例3: mayor_data
def mayor_data(url):
page = lxmlize(url)
# TODO: Consider getting photo. It's on a separate page.
name_text = page.xpath('//p[contains(text(), "Worship Mayor")]/text()')[0]
name = ' '.join(name_text.split()[3:]) # TODO: probably too brittle
email = page.xpath('//a[contains(@href, "mailto")]/text()')[0]
p = Legislator(name=name, post_id='Mississauga', role='Mayor')
p.add_source(url)
p.add_contact('email', email, None)
return p
示例4: scrape_mayor
def scrape_mayor(url):
page = lxmlize(url)
name = page.xpath('//div[@id="printAreaContent"]/h1/strong/text()')[0].replace('Mayor', '').strip()
address = page.xpath('//strong[contains(text(), "mail")]/parent::p/text()')[1].replace(':', '').strip()
phone = page.xpath('//strong[contains(text(), "phone")]/parent::p/text()')[1].split()[1]
p = Legislator(name=name, post_id='Caledon', role='Mayor')
p.add_source(COUNCIL_PAGE)
p.add_source(url)
p.image = page.xpath('//h2[contains(text(), "About me")]/img/@src')[0]
p.add_contact('address', address, 'legislature')
p.add_contact('voice', phone, 'legislature')
return p
示例5: councillor_data
def councillor_data(url, name, ward):
page = lxmlize(url)
# email is, sadly, a form
photo_url = urljoin(url, page.xpath('string(//img[@class="bio_pic"]/@src)'))
phone = page.xpath('string(//td[contains(., "Phone")]/following-sibling::td)')
email = (page.xpath('string(//tr[contains(., "Email")]//a/@href)').
split('=')[1] + '@winnipeg.ca')
p = Legislator(name=name, post_id=ward, role='Councillor')
p.add_source(COUNCIL_PAGE)
p.add_source(url)
p.add_contact('email', email, None)
p.add_contact('voice', phone, 'legislature')
p.image = photo_url
return p
示例6: scrape_person
def scrape_person(url):
page = lxmlize(url)
role, name = page.xpath('string(//title)').split(' ', 1)
photo_url = page.xpath('string(//div[@id="content"]//img[@style]/@src)')
email = page.xpath('string(//a[contains(@href, "mailto:")])')
phone = page.xpath('string(//li[contains(text(), "Phone:")])')
p = Legislator(name=name, post_id='Burnaby', role=role, image=photo_url)
p.add_source(COUNCIL_PAGE)
p.add_source(url)
p.add_contact('email', email, None)
if phone:
p.add_contact('voice', phone, 'legislature')
return p