我试图从这个链接中提取一个特定的文本:
http://www1.folha.uol.com.br/fsp/mercado/index-20121030.shtml
我编写了这个函数来查找和提取一段文本:
def manchete_11112011_30102012(b):
soup = make_soup(b)
data = [span.string for span in soup.find("font")]
noticias = [b.text for b in soup.findAll("a")]
return {"noticias": noticias,
"data": data}
好吧。我的问题是“data”行。当它运行时,它什么也不返回。当我写下跨度.string“它返回”[无]“当我写时”span.文本“返回”[u”]“
这是我要找的HTML代码。我需要<span id="spanLongDate">
内的文本内容:
有没有其他方法可以提取文本?我的意思是,我是不是写错了代码,或者文本格式不兼容?“[u”]”是什么意思?在
如果你只想要日期,你应该在其他地方找。如果你把汤倒出来,然后搜索2012年,你会在很多地方看到它。用下面的代码很容易把它从标题中去掉。在
要找到
id = spanLongDate
,请使用以下片段请注意,如果必须找到多个实例请使用
.find_all
预计到达时间:
根据你下面的评论,我去查看了页面源代码,甚至在我的机器上运行了它。这里有一个函数,可以让您转储beauthoulsoup看到的内容。这很有帮助,因为有时在浏览器中查看源代码时,它看不到您看到的内容。在
^{pr2}$当我把它打印出来并搜索“spanLongDate”时,我得到了以下感兴趣的片段。在
这里面没有圣保罗的文字。然后我在Chrome浏览器中点击F12找到原始源代码,
spanLongDate
<div>
中也没有文本。在也许页面更新了?在
相关问题 更多 >
编程相关推荐