當前位置: 首頁>>代碼示例>>Python>>正文


Python parser.feed方法代碼示例

本文整理匯總了Python中html.parser.feed方法的典型用法代碼示例。如果您正苦於以下問題:Python parser.feed方法的具體用法?Python parser.feed怎麽用?Python parser.feed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在html.parser的用法示例。


在下文中一共展示了parser.feed方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_beta_branch_name

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def get_beta_branch_name(game_name="ets2"):
    """
    Get the current required beta branch name to comply with TruckersMP.

    If downgrade is needed, this returns a branch name that can be used
    to install TruckersMP-compatible versions of games (e.g. "temporary_1_36")
    on success or None on error.
    If downgrade is not needed, this returns None.
    """
    try:
        parser = DowngradeHTMLParser()
        with urllib.request.urlopen(URL.truckersmp_stats) as f:
            parser.feed(f.read().decode("utf-8"))

        if parser.data[game_name]:
            version = get_supported_game_versions()[game_name].split(".")
            return "temporary_{}_{}".format(version[0], version[1])
        return None
    except Exception:
        return None 
開發者ID:lhark,項目名稱:truckersmp-cli,代碼行數:22,代碼來源:__init__.py

示例2: github_contrib

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def github_contrib(user, year):
    """ Get GitHub user daily contribution """

    # Check for a cached version (file)
    filename = "github-{0}-{1}.html".format(user, year)
    if os.path.exists(filename):
        with open(filename) as file:
            contents = file.read()
    # Else get file from GitHub
    else:
        url = "https://github.com/users/{0}/contributions?to={1}-12-31"
        url = url.format(user, year)
        contents = str(urllib.request.urlopen(url).read())
        with open(filename, "w") as file:
            file.write(contents)

    # Parse result (html)
    n = 1 + (date(year, 12, 31) - date(year, 1, 1)).days
    C = -np.ones(n, dtype=int)
    class HTMLParser(html.parser.HTMLParser):
        def handle_starttag(self, tag, attrs):
            if tag == "rect":
                data = {key:value for (key,value) in attrs}
                date = dateutil.parser.parse(data["data-date"])
                count = int(data["data-count"])
                day = date.timetuple().tm_yday - 1
                if count > 0:
                    C[day] = count

    parser = HTMLParser()
    parser.feed(contents)
    return C 
開發者ID:rougier,項目名稱:calendar-heatmap,代碼行數:34,代碼來源:github-activity.py

示例3: count

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def count(filename):
        if not HtmlWordCounter.can_count(filename):
            return 0
        parser = HtmlWordCounter.__HtmlParser()
        with open(filename, encoding="utf-8") as file:
            parser.feed(file.read())
        return parser.count 
開發者ID:lovexiaov,項目名稱:python-in-practice,代碼行數:9,代碼來源:wordcount2.py

示例4: _run_check

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def _run_check(self, source, expected_events, collector=None):
        if collector is None:
            collector = self.get_collector()
        parser = collector
        for s in source:
            parser.feed(s)
        parser.close()
        events = parser.get_events()
        if events != expected_events:
            self.fail("received events did not match expected events" +
                      "\nSource:\n" + repr(source) +
                      "\nExpected:\n" + pprint.pformat(expected_events) +
                      "\nReceived:\n" + pprint.pformat(events)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:15,代碼來源:test_htmlparser.py

示例5: test_convert_charrefs_dropped_text

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def test_convert_charrefs_dropped_text(self):
        # #23144: make sure that all the events are triggered when
        # convert_charrefs is True, even if we don't call .close()
        parser = EventCollector(convert_charrefs=True)
        # before the fix, bar & baz was missing
        parser.feed("foo <a>link</a> bar &amp; baz")
        self.assertEqual(
            parser.get_events(),
            [('data', 'foo '), ('starttag', 'a', []), ('data', 'link'),
             ('endtag', 'a'), ('data', ' bar & baz')]
        ) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:13,代碼來源:test_htmlparser.py

示例6: _parse_error

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def _parse_error(self, source):
        def parse(source=source):
            parser = self.get_collector()
            parser.feed(source)
            parser.close()
        with self.assertRaises(html.parser.HTMLParseError):
            with self.assertWarns(DeprecationWarning):
                parse() 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:10,代碼來源:test_htmlparser.py

示例7: serialize

# 需要導入模塊: from html import parser [as 別名]
# 或者: from html.parser import feed [as 別名]
def serialize(result):
    """For a given Met result, map that to our database"""
    imageinfos = result['ImageInfo']
    thumbnail = None
    url = None
    for info in imageinfos:
        if info['PrimaryDisplay']:
            # Use this one
            thumbnail = ENDPOINT_BASE_IMAGE_URL + info['Thumbnail']
            url = ENDPOINT_BASE_IMAGE_URL + info['LargeWebsite']
            break
    if not url:
        log.warning("Did not get an image URL for %s", result)
        return
    image = models.Image(url=url)
    image.provider = PROVIDER_NAME
    image.source = SOURCE_NAME

    # Creator might be a few fields
    tombstone = result['Tombstone']
    creator_names = []
    for t in tombstone:
        if t['Name'] in CREATOR_LABELS:
            val = t['Value']
            parser = CreatorParser()
            parser.feed(val)
            creator_names.append(" ".join(parser.out))
    if len(creator_names) > 0:
        image.creator = ", ".join(creator_names)

    image.thumbnail = thumbnail
    image.license = "cc0"
    image.license_version = '1.0'
    image.foreign_identifier = result['CollectionObject']['CRDID']
    image.foreign_landing_url = FOREIGN_LANDING_BASE_URL + str(image.foreign_identifier)
    image.title = result['CollectionObject']['Title']
    image.identifier = signals.create_identifier(image.url)
    image.last_synced_with_source = timezone.now()
    try:
        image.save()
        log.info("Adding image %s-%s (%s) identifier %s", image.title, image.creator, image.foreign_identifier, image.identifier)
    except IntegrityError as e:
        log.warn(e)
        pass
    return image 
開發者ID:cc-archive,項目名稱:open-ledger,代碼行數:47,代碼來源:handler_met.py


注:本文中的html.parser.feed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。