• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.CanadianLegislator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:32,代码来源:people.py


示例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
开发者ID:rhymeswithcycle,项目名称:scrapers-ca,代码行数:28,代码来源:people.py


示例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
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:13,代码来源:people.py


示例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
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:14,代码来源:people.py


示例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
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:16,代码来源:people.py


示例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
开发者ID:fchagnon,项目名称:scrapers-ca,代码行数:15,代码来源:people.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.CanadianPerson类代码示例发布时间:2022-05-26
下一篇:
Python utils.BaseWS类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap