【发布时间】:2021-06-03 16:15:29
【问题描述】:
我通过beautifulsoup在python中有一段HTML代码,但无法从中检索到所需的时间标签。
HTML is called K:
<time class="dtstart" datetime="05 December 201710:30 AM GMT" id="x-event-date" xcdate="1512469800950">
<a class="action pull-right print-cat" data-href="/en/aus/2017/some-url-data-l17407.html" data-modalid="catalogueModal" data-toggle="modal" href="/en/auctions/ecatalogue/lot.print.L17407.html" style="display: none;">Print My Catalogue (0)</a>
<ul class="breadcrumb inline">
<li>
<a href="/en/aus/2017/some-url-data-l17407.html"><span class="active">Smartphone and watches</span></a>
</li>
</ul>
</time>
我可以提取除时间以外的所有标签:
K.a :
<a class="action pull-right print-cat" data-href="/en/aus/2017/some-url-data-l17407.html" data-modalid="catalogueModal" data-toggle="modal" href="/en/auctions/ecatalogue/lot.print.L17407.html" style="display: none;">Print My Catalogue (0)</a>
K.li:
<li>
<a href="/en/aus/2017/some-url-data-l17407.html"><span class="active">Smartphone and watches</span></a>
</li>
K.time:
Nothing prints
我也尝试了以下解决方案:
K.find('time', {'class':'dtstart'})
Nothing prints
K.find('a', {'class':'action pull-right print-cat'})
<a class="action pull-right print-cat" data-href="/en/aus/2017/some-url-data-l17407.html" data-modalid="catalogueModal" data-toggle="modal" href="/en/auctions/ecatalogue/lot.print.L17407.html" style="display: none;">Print My Catalogue (0)</a>
当我们检查 K 时,我们会看到以下内容:
Signature: K(*args, **kwargs)
Type: Tag
String form:
<time class="dtstart" datetime="05 December 201710:30 AM GMT" id="x-event-date" xcdate="1512469800950">
<a class="action pull-right print-cat" data-href="/en/aus/2017/some-url-data-l17407.html" data-modalid="catalogueModal" data-toggle="modal" href="/en/auctions/ecatalogue/lot.print.L17407.html" style="display: none;">Print My Catalogue (0)</a>
<ul class="breadcrumb inline">
<li>
<a href="/en/aus/2017/some-url-data-l17407.html"><span class="active">Smartphone and watches</span></a>
</li>
</ul>
</time>
Length: 5
File: ~/.local/lib/python3.6/site-packages/bs4/element.py
Source:
时间标签怎么可能没有被提取?
【问题讨论】:
-
源网址和预期输出值是多少?您是否确认它不是动态加载的?似乎该网页正在为此制作额外的 xhr,或者正在使用 js 从其他地方计算/填充
标签: python html beautifulsoup tags