【问题标题】:How can i crawl web data that not in tags如何抓取不在标签中的网络数据
【发布时间】:2017-10-22 19:40:04
【问题描述】:
<div id="main-content" class="content">
<div class="metaline">
<span class="article-meta author">jorden</span>
</div>
 "
 1.name:jorden> 
 2.age:28

  --
 "
 <span class="D2"> from 111.111.111.111 </span>
  </div>

我只需要

1.name:乔丹
2.年龄:28

xxx.select('#main-content') 这将返回所有内容,但我只需要其中的一部分。 因为它们不在任何标签中,我不知道该怎么做。

【问题讨论】:

  • 网站的任何链接?

标签: python html beautifulsoup web-crawler python-requests


【解决方案1】:

您想在有问题的文本(在您的情况下为&lt;div class="metaline"&gt;)找到标签 before,然后查看 HTML 解析树中的 next 兄弟:

text = soup.find("div", class_='metaline').next_sibling
print(text)
# "
# 1.name:jorden> 
# 2.age:28
#
#  --
# "
# 

获得原始文本后,将其剥离,等等。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    相关资源
    最近更新 更多