当前位置: 首页>>代码示例>>Python>>正文


Python CanadianLegislator.add_contact方法代码示例

本文整理汇总了Python中utils.CanadianLegislator.add_contact方法的典型用法代码示例。如果您正苦于以下问题:Python CanadianLegislator.add_contact方法的具体用法?Python CanadianLegislator.add_contact怎么用?Python CanadianLegislator.add_contact使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.CanadianLegislator的用法示例。


在下文中一共展示了CanadianLegislator.add_contact方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_people

# 需要导入模块: from utils import CanadianLegislator [as 别名]
# 或者: from utils.CanadianLegislator import add_contact [as 别名]
  def get_people(self):
    page = lxmlize(COUNCIL_PAGE)

    councillor_trs = [tr for tr in page.xpath('//table//tr[1]') if len(tr) == 2][:-1]
    for councillor_tr in councillor_trs:
      desc = [text.strip() for text in councillor_tr.xpath('.//text()[normalize-space()]') if text.strip()]

      if len(desc) == 3:
        role = 'Maire'
        district = u'Saint-Jérôme'
      else:
        role = 'Conseiller'
        district = desc[0].replace(u'numéro ', '')

      name = desc[-3]
      phone = desc[-2]
      email = desc[-1]

      image = councillor_tr.xpath('string(.//img/@src)')[0]
      
      p = Legislator(name=name, post_id=district, role=role)
      p.add_source(COUNCIL_PAGE)
      p.image = image
      p.add_contact('voice', phone, 'legislature')
      p.add_contact('email', email, None)
      yield p
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:28,代码来源:people.py

示例2: get_people

# 需要导入模块: from utils import CanadianLegislator [as 别名]
# 或者: from utils.CanadianLegislator import add_contact [as 别名]
    def get_people(self):
        # mayor first, can't find email
        page = lxmlize(MAYOR_URL)
        photo_url = page.xpath('string(//img/@src[contains(., "Maire")])')
        name = page.xpath('string(//td[@class="contenu"]/text()[last()])')
        p = Legislator(name=name, post_id=u"Trois-Rivières", role="Maire", image=photo_url)
        p.add_source(MAYOR_URL)
        yield p

        resp = requests.get(COUNCIL_PAGE)
        # page rendering through JS on the client
        page_re = re.compile(r'createItemNiv3.+"District (.+?)".+(index.+)\\"')
        for district, url_rel in page_re.findall(resp.text):
            if district not in ("des Estacades", "des Plateaux", "des Terrasses", "du Sanctuaire"):
                district = re.sub("\A(?:de(?: la)?|des|du) ", "", district)

            url = urljoin(COUNCIL_PAGE, url_rel)
            page = lxmlize(url)
            name = page.xpath("string(//h2)")
            email = page.xpath('string(//a/@href[contains(., "mailto:")])')[len("mailto:") :]
            photo_url = page.xpath('string(//img/@src[contains(., "Conseiller")])')
            p = Legislator(name=name, post_id=district, role="Conseiller", image=photo_url)
            p.add_source(url)
            p.add_contact("email", email, None)
            yield p
开发者ID:rhymeswithcycle,项目名称:scrapers-ca,代码行数:27,代码来源:people.py

示例3: councillor_data

# 需要导入模块: from utils import CanadianLegislator [as 别名]
# 或者: from utils.CanadianLegislator import add_contact [as 别名]
def councillor_data(url, name, ward):
  page = lxmlize(url)
  # sadly, email is a form on a separate page
  phone = page.xpath('string(//strong[contains(., "Phone")])').split(':')[1]
  photo_url_rel = page.xpath('string(//div[@id="contentcontainer"]//img/@src)')
  photo_url = urljoin(url, photo_url_rel)
  m = Legislator(name=name, post_id=ward, role='Councillor')
  m.add_source(COUNCIL_PAGE)
  m.add_source(url)
  m.add_contact('voice', phone, 'legislature')
  m.image = photo_url
  yield m
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:14,代码来源:people.py

示例4: mayor_data

# 需要导入模块: from utils import CanadianLegislator [as 别名]
# 或者: from utils.CanadianLegislator import add_contact [as 别名]
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
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:15,代码来源:people.py

示例5: scrape_mayor

# 需要导入模块: from utils import CanadianLegislator [as 别名]
# 或者: from utils.CanadianLegislator import add_contact [as 别名]
  def scrape_mayor(self, div):
    url = div.attrib['href']
    page = lxmlize(url)

    name = div.text_content().replace('Mayor ', '')
    contact_url = page.xpath('//ul[@class="navSecondary"]//a[contains(text(),"Contact")]')[0].attrib['href']
    page = lxmlize(contact_url)

    contact_div = page.xpath('//div[@class="col"][2]')[0]

    address = contact_div.xpath('.//p[1]')[0].text_content()
    address = re.findall(r'(City of Greater .*)', address, flags=re.DOTALL)[0]
    phone = contact_div.xpath('.//p[2]')[0].text_content()
    phone = phone.replace('Phone: ', '')
    fax = contact_div.xpath('.//p[3]')[0].text_content()
    fax = fax.split(' ')[-1]
    email = contact_div.xpath('//a[contains(@href, "mailto:")]')[0].text_content()

    p = Legislator(name=name, post_id='Greater Sudbury', role='Mayor')
    p.add_source(COUNCIL_PAGE)
    p.add_source(contact_url)
    p.add_contact('address', address, 'legislature')
    p.add_contact('voice', phone, 'legislature')
    p.add_contact('fax', fax, 'legislature')
    p.add_contact('email', email, None)
    return p
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:28,代码来源:people.py


注:本文中的utils.CanadianLegislator.add_contact方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。