首页 \ 问答 \ 使用C ++和Boost获取当前时间(以毫秒为单位)(Get current time in milliseconds using C++ and Boost)

使用C ++和Boost获取当前时间(以毫秒为单位)(Get current time in milliseconds using C++ and Boost)

在我的线程(使用boost :: thread)中,我需要检索当前时间(ms)或更少,并转换成ms:

其实在这里阅读我发现这个:

tick = boost::posix_time::second_clock::local_time();
now  = boost::posix_time::second_clock::local_time();

似乎工作,但是在我需要有一个很长的毫秒值之后...

我该怎么做?


In my thread (using boost::thread) I need to retrieve the current time in ms or less and to convert into ms:

Actually, reading here I've found this:

tick = boost::posix_time::second_clock::local_time();
now  = boost::posix_time::second_clock::local_time();

And seems to work, but after I need to have a long value of the milliseconds of the now...

How can I do it?


原文:https://stackoverflow.com/questions/6734375
更新时间:2022-04-22 10:04

最满意答案

获取p内的每个strong标签,然后获取它的父母和下一个父母的兄弟姐妹,直到有另一个带有strong标签的p标签或没有更多的兄弟姐妹:

from lxml.html import fromstring


html_data = """<div class="TabItem">
    <p><strong>Product Composition</strong></p>
    <p>93% Polyamide 7% Elastane</p>
    <p>Lining: 100% Polyester</p><p>Dress Length: 90 cm</p>

    <p><strong>Product Attributes;</strong></p>
    <p>: Boat Neck, Long Sleeve, Midi, Zip, Concealed, Laced, Side</p>
    <p>Lining Type: Full Lining</p>
</div>"""

tree = fromstring(html_data)
data = {}
for strong in tree.xpath('//p/strong'):
    parent = strong.getparent()

    description = []
    next_p = parent.getnext()
    while next_p is not None and not next_p.xpath('.//strong'):
        description.append(next_p.text)
        next_p = next_p.getnext()

    data[strong.text] = " ".join(description)

print data

打印:

{'Product Composition': '93% Polyamide 7% Elastane Lining: 100% Polyester', 
 'Product Attributes;': ': Boat Neck, Long Sleeve, Midi, Zip, Concealed, Laced, Side Lining Type: Full Lining'}

Get every strong tag inside p, then get it's parent and next parent's siblings until there is another p tag with strong tag inside or no more siblings left:

from lxml.html import fromstring


html_data = """<div class="TabItem">
    <p><strong>Product Composition</strong></p>
    <p>93% Polyamide 7% Elastane</p>
    <p>Lining: 100% Polyester</p><p>Dress Length: 90 cm</p>

    <p><strong>Product Attributes;</strong></p>
    <p>: Boat Neck, Long Sleeve, Midi, Zip, Concealed, Laced, Side</p>
    <p>Lining Type: Full Lining</p>
</div>"""

tree = fromstring(html_data)
data = {}
for strong in tree.xpath('//p/strong'):
    parent = strong.getparent()

    description = []
    next_p = parent.getnext()
    while next_p is not None and not next_p.xpath('.//strong'):
        description.append(next_p.text)
        next_p = next_p.getnext()

    data[strong.text] = " ".join(description)

print data

prints:

{'Product Composition': '93% Polyamide 7% Elastane Lining: 100% Polyester', 
 'Product Attributes;': ': Boat Neck, Long Sleeve, Midi, Zip, Concealed, Laced, Side Lining Type: Full Lining'}

相关问答

更多
  • 如果您的程序是用.NET编写的,那么您可以查看有关实现线程安全字典的最佳方法的相关问题,链接和C#示例代码...... If your program is written in .NET, you can take a look at this related question regarding the best way of implementing a thread-safe Dictionary, with links and C# sample code…
  • 获取p内的每个strong标签,然后获取它的父母和下一个父母的兄弟姐妹,直到有另一个带有strong标签的p标签或没有更多的兄弟姐妹: from lxml.html import fromstring html_data = """

    Product Composition

    93% Polyamide 7% Elastane

    Lining: 100% Polyester

  • 使用典型的for循环: h = {} for k,v in o.items(): h.update({k: v.title() + '-Hundred'}) 结果 : {1: 'One-Hundred', 2: 'Two-Hundred'} 这种工作方式非常简单 : 首先初始化新的字典( h = {} ) - 然后它将是空的。 接下来使用密钥和o字典items()中的值( k , v )设置循环。 最后一步是用键,值和字符串update()每次迭代的h字典。 ({ k := key, v = v ...
  • 您可以创建存储要复制的字段名称的tuple或list ,并遍历每个元素 new_dictionary = {k: config[k] for k in ('username', 'password')} You can just create tuple or list that stores names of fields that you want to be copied and iterate through every element new_dictionary = {k: config[k] ...
  • 你在keyword_check明确地重置你的字典,所以它当然不能按预期工作。 解决这个问题的一个方法是在main定义你的dict,并将它作为参数传递给另一个函数: def main(): list = [["haha", "amazed", "amazing"], ["great", "wow", "awesome"]] dictionary = {} print(keyword_check(list[0], dictionary)) print(keyword_check( ...
  • 您可以在字典理解中使用re.findall() : In [11]: {k: re.findall(r'(?:K|M){6,18}', v) for k, v in li.items()} Out[11]: {'id1': ['KKKKKK', 'MMMMMMMMMMMMMMM'], 'id2': ['KKKKKM', 'KKKKKK']} r'(?:K|M){6,18}'是一个正则表达式,它将匹配K或M长度为6到18的任何子字符串。 You can use re.findall() within a d ...
  • 您只需创建Int: [String]类型的字典Int: [String] class MyWidget : NSObject { // empty fieldData dictionary of type Int: [String] var fieldData = [Int: [String]]() } //添加这样的数据 fieldData[0] = ["Acme", "Contoso", "Tradewinds"] fieldData[1] = ["Model1", "Model2", "Mode ...
  • 你可以这样做 def make_scores_dict(names, scores): return dict(zip(names, scores)) 要修复您尝试执行的操作: def make_scores_dict(names, scores): scores_dict = {} for i in range(len(names)): scores_dict[names[i]] = scores[i] return scores_dict 要么 de ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)