我使用Beautifulsoup解析带有"class"属性的html元素时遇到问题.代码看起来像这样
soup = BeautifulSoup(sdata)
mydivs = soup.findAll('div')
for div in mydivs:
if (div["class"] == "stylelistrow"):
print div
Run Code Online (Sandbox Code Playgroud)
我在脚本完成后"同一行"收到错误.
File "./beautifulcoding.py", line 130, in getlanguage
if (div["class"] == "stylelistrow"):
File "/usr/local/lib/python2.6/dist-packages/BeautifulSoup.py", line 599, in __getitem__
return self._getAttrMap()[key]
KeyError: 'class'
Run Code Online (Sandbox Code Playgroud)
我该怎么摆脱或这个错误?
如何检索网页的链接并使用Python复制链接的URL地址?
我的Visual Studio代码在Windows机器上,即使在更新文件之后仍然向我显示文件的先前内容,notepad ++而不是以相同的方式运行.
有没有办法以某种方式清理缓存,以便每次都收到新鲜的内容?
我有以下html(标记为\n的换行符):
...
<tr>
<td class="pos">\n
"Some text:"\n
<br>\n
<strong>some value</strong>\n
</td>
</tr>
<tr>
<td class="pos">\n
"Fixed text:"\n
<br>\n
<strong>text I am looking for</strong>\n
</td>
</tr>
<tr>
<td class="pos">\n
"Some other text:"\n
<br>\n
<strong>some other value</strong>\n
</td>
</tr>
...
Run Code Online (Sandbox Code Playgroud)
如何找到我要找的文字?下面的代码返回第一个找到的值,所以我需要以某种方式过滤固定文本.
result = soup.find('td', {'class' :'pos'}).find('strong').text
Run Code Online (Sandbox Code Playgroud)
更新.如果我使用以下代码:
title = soup.find('td', text = re.compile(ur'Fixed text:(.*)', re.DOTALL), attrs = {'class': 'pos'})
self.response.out.write(str(title.string).decode('utf8'))
Run Code Online (Sandbox Code Playgroud)
然后它返回固定文本:.
AlexKolpa/fab-toolbar当我注意到动画无法正常工作时,我最近即将导入该库,即使我按照以下链接中给出的所有指示操作:
https://github.com/AlexKolpa/fab-toolbar
我的代码如下:
主要活动
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Toast;
import com.github.alexkolpa.fabtoolbar.FabToolbar;
public class MainActivity extends ActionBarActivity implements View.OnClickListener{
private FabToolbar fabToolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fabToolbar = ((FabToolbar) findViewById(R.id.fab_toolbar));
fabToolbar.setColor(getResources().getColor(R.color.blue));
// findViewById(R.id.attach).setOnClickListener(this);
findViewById(R.id.attach).setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Log.e("SOMETHING","SOMETHING");
fabToolbar.show();
}
});
}
@Override
public void onClick(View v){
Toast.makeText(this,"This is a button click!", Toast.LENGTH_SHORT).show();
fabToolbar.hide();
}
}Run Code Online (Sandbox Code Playgroud)
主要活动布局: …
处理音频的最佳方法是什么,以便输出正在播放的音符?我正在为大学任务创建一个吉他调音器,我是Android开发的新手.
我已经看过Android上关于从Google API录制声音的示例,但我想知道从那里去哪里?
我知道我必须进行傅立叶变换,或其他什么来获得频率,只是想知道是否有人对如何做到这一点有任何建议?
一旦我们能够在屏幕上显示正确的频率,我们将完成大部分项目.
谢谢你的帮助.
要点:
我已成功使用VBA执行以下操作:
使用getElementsByName登录网站
选择将生成的报告的参数(使用getelementsby ...)
需要注意的重要事项 - 该网站是客户端的
以上是简单的部分,困难的部分如下:
单击iframe中将数据集导出到csv的gif图像
我尝试过以下方法:
Dim idoc As HTMLDocument
Dim iframe As HTMLFrameElement
Dim iframe2 As HTMLDocument
Set idoc = objIE.document
Set iframe = idoc.all("iframename")
Set iframe2 = iframe.contentDocument
Do Until InStr(1, objIE.document.all("iframename").contentDocument.innerHTML, "img.gif", vbTextCompare) = 0
DoEvents
Loop
Run Code Online (Sandbox Code Playgroud)
为上面的逻辑提供一些背景 -
正是在这条线上它说"对象不支持这个属性或方法"
还尝试通过a元素和href属性访问iframe gif,但这完全失败了.我也尝试从其源URL抓取图像,但所有这一切都将我带到图像所在的页面.
注意:iframe没有ID,奇怪的是gif图像没有"onclick"元素/事件
最后的考虑 - 尝试使用R来抓取iframe
访问iframe的HTML节点很简单,但是尝试访问iframe的属性,随后表的节点被证明是不成功的.它返回的只是"Character(0)"
library(rvest)
library(magrittr)
Blah <-read_html("web address redacted") %>%
html_nodes("#iframe")%>%
html_nodes("#img")%>%
html_attr("#src")%>%
#read_html()%>%
head()
Blah
Run Code Online (Sandbox Code Playgroud)
只要ai包含read_html,脚本就会返回以下错误:
if(grepl("<|>",x)){:参数的长度为零时出错
我怀疑这是指字符(0)
感谢这里的任何指导!
非常感谢,
HTML
<div …Run Code Online (Sandbox Code Playgroud) 我正在研究文本分类问题,也就是说,给定一些文本,我需要为其分配某些给定的标签.
我尝试过使用Facebook的快速文本库,它有两个我感兴趣的实用工具:
A)具有预训练模型的单词向量
B)文本分类实用程序
但是,似乎这些是完全独立的工具,因为我无法找到合并这两个实用程序的任何教程.
我想要的是能够通过利用Word-Vectors的预训练模型对某些文本进行分类.有没有办法做到这一点?
我遇到了几个可序列化的异常,并且我在Flink的互联网和文档上进行了一些搜索;有一些著名的解决方案,如瞬态、扩展序列化等。每次异常的起源都非常清楚,但就我而言,我无法找到它到底在哪里没有序列化。
问:遇到这种异常应该如何调试?
A.斯卡拉:
class executor ( val sink: SinkFunction[List[String]] {
def exe(): Unit = {
xxx.....addSink(sinks)
}
}
Run Code Online (Sandbox Code Playgroud)
B.scala:
class Main extends App {
def createSink: SinkFunction[List[String]] = new StringSink()
object StringSink {
// static
val stringList: List[String] = List()
}
// create a testing sink
class StringSink extends SinkFunction[List[String]] {
override def invoke(strs: List[String]): Unit = {
// add strs into the variable "stringList" of the compagin object StringSink
}
}
new executor(createSink()).exe()
// then do …Run Code Online (Sandbox Code Playgroud) 我在运行 Python 2.7.8 的 MacOSX 上使用 BeautifulSoup4。我很难从以下 html 代码中提取信息
<tbody tabindex="0" class="yui-dt-data" id="yui_3_5_0_1_1408418470185_1650">
<tr id="yui-rec0" class="yui-dt-first yui-dt-even">
<td headers="yui-dt0-th-rank" class="rank yui-dt0-col-rank"></td>
</tr>
<tr id="yui-rec1" class="yui-dt-odd">...</tr>
<tr id="yui-rec2" class="yui-dt-even">...</tr>
</tbody>
Run Code Online (Sandbox Code Playgroud)
我似乎无法获取表格或其中的任何内容,因为 BS 和/或 python 似乎无法识别带有连字符的值。所以通常的代码,就像
Table = soup.find('tbody',{'class':'yui-dt-data'})
Run Code Online (Sandbox Code Playgroud)
或者
Row2 = Table.find('tr',{'id':'yui-rec2'})
Run Code Online (Sandbox Code Playgroud)
只返回一个空对象(不是 NONE,只是空)。我对 BS4 或 Python 并不陌生,我之前已经从这个网站提取过信息,但现在的类名与我以前提取时不同。现在一切都有连字符。有没有办法让 Python 识别连字符或解决方法?
我需要使我的代码具有通用性,以便我可以在多个具有相同类名的页面上运行它。不幸的是,id中的属性<tbody>对于该特定表来说是唯一的,因此我无法使用它来跨网页识别该表。
任何帮助,将不胜感激。提前致谢。
web-scraping ×5
python ×4
html ×3
android ×2
apache-flink ×1
audio ×1
excel ×1
fasttext ×1
flink-cep ×1
gradle ×1
html-parsing ×1
hyperlink ×1
iframe ×1
java ×1
nlp ×1
python-2.7 ×1
vba ×1
word2vec ×1