我的硬盘上有一些html文件,我想用jquery来从中提取数据.这可以用cheerio吗?我试过给当地的路径提供cheerio,但它不起作用.我有一个想法是在节点中创建一个Web服务器,从html文件中读取,然后通过服务器将其传送给cheerio-这样吗
Phantomjs有这两个非常方便的回调onLoadStarted
,onLoadFinished
它允许你在页面加载时基本上暂停执行.但我一直在搜索,如果你click()
提交按钮或超链接,我找不到相应的.发生了类似的页面加载,但onLoadStarted
我没有调用此事件,因为没有明确的page.open()
发生.我正试图找出一种干净的方法来暂停执行此负载.
一个解决方案显然是嵌套的setTimeout,但我想避免这种情况,因为它是hacky并依赖于试验和错误而不是可靠和更强大的东西,如测试某事或等待事件.
我错过了这种页面加载的特定回调吗?或者也许有某种通用的代码模式可以处理这种事情?
编辑:
我还没弄明白如何让它暂停.这是onLoadStarted()
我调用click()
命令时不调用该函数的代码:
var loadInProgress = false;
page.onLoadStarted = function() {
loadInProgress = true;
console.log("load started");
};
page.onLoadFinished = function() {
loadInProgress = false;
console.log("load finished");
};
page.open(loginPage.url, function (status) {
if (status !== 'success') {
console.log('Unable to access network');
fs.write(filePath + errorState, 1, 'w');
phantom.exit();
} else {
page.evaluate(function (loginPage, credentials) {
console.log('inside loginPage evaluate function...\n')
document.querySelector('input[id=' + loginPage.userId + ']').value = credentials.username; …
Run Code Online (Sandbox Code Playgroud) 该Parcelable
文件说,该CREATOR
字段必须是静态的,但是当我尝试实施这种方式我得到错误"内部类不能有静态的声明".
我试图通过将我CategoryButton
放在一个单独的类(不将其声明为内部类MainActivity
)来解决这个问题,但后来我无法调用getApplicationContext()
构造函数来传递给super.
public class MainActivity extends ActionBarActivity {
private class CategoryButton extends Button implements Parcelable{
private ArrayList<CategoryButton> buttons = null;
private RelativeLayout.LayoutParams params = null;
public CategoryButton(Context context){
super(context);
};
public void setButtons(ArrayList<CategoryButton> buttons){
this.buttons = buttons;
}
public void setParams(RelativeLayout.LayoutParams params){
this.params = params;
}
public ArrayList<CategoryButton> getButtons(){
return this.buttons;
}
public RelativeLayout.LayoutParams getParams(){
return this.params;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int …
Run Code Online (Sandbox Code Playgroud) 我在安装Android Studio时出现问题,每次在设计视图中将小部件添加到布局时都会崩溃.所以我下载了碰巧是预览版本的最新版本.这解决了崩溃问题.它不是安装程序,只是压缩了所有文件.所以我删除了旧的Android Studio版本,并将其替换为此预览版本.
现在我每次打开AS时都会收到此错误:
AssertionError: build-tools-23.0.0 doesn't match build-tools-23.0.0-preview
此外,当我尝试构建应用程序时,AS不再识别我的手机,因此无法对其进行测试.我不确定这两个问题是否相关.
问题是我以某种方式设置了活动边框的样式,使其呈亮橙色,并且所有边的厚度约为 5 像素。我不记得是什么命令导致了这个。
我使用 line 来设置非活动边框的样式没有问题set -g pane-border-style fg=brightblack
。但是使用相同的格式来设置活动边框的样式不会set -g pane-active-border-style fg=white
产生任何效果。
也许我试图设计错误的东西?是否有其他一些窗格属性与活动窗格重叠?
我正在尝试运行我在java基本路径课程中找到的示例java程序.我想使用eclipse逐步完成它,以便更好地了解正在发生的事情.Person类很好没有错误但是MRTest类最后有一个错误,对于调用它的类型,stream()方法是未定义的.我不知道如何解决这个问题.
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.Set;
import java.util.HashSet;
import java.time.chrono.IsoChronology;
public class MRTest {
// The method transferElements copies elements from one collection to
// another
public static <T, SOURCE extends Collection<T>, DEST extends Collection<T>>
DEST transferElements(
SOURCE sourceCollection,
Supplier<DEST> collectionFactory) {
DEST result = collectionFactory.get();
for (T t : sourceCollection) {
result.add(t);
}
return result;
}
public static void main(String... args) {
List<Person> roster = Person.createRoster();
for (Person p : …
Run Code Online (Sandbox Code Playgroud) 我试图理解一些python 2.5代码,我遇到了这种模式:
def __init__(self, matrix, top_buttons, side_buttons, config_button):
raise isinstance(matrix, ButtonMatrixElement) or AssertionError
raise matrix.width() == 8 and matrix.height() == 8 or AssertionError
raise isinstance(top_buttons, tuple) or AssertionError
raise len(top_buttons) == 8 or AssertionError
raise isinstance(side_buttons, tuple) or AssertionError
raise len(side_buttons) == 8 or AssertionError
raise isinstance(config_button, ButtonElement) or AssertionError
Run Code Online (Sandbox Code Playgroud)
我尝试在shell中使用一些简单的条件语句测试它,如下所示:
>>> str = 'hello'
>>> raise len(str) == 5 or AssertionError
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
raise len(str) == 5 or AssertionError
TypeError: …
Run Code Online (Sandbox Code Playgroud) 我只是想提一下,我尝试了一些来自博客的技术来获取用户输入但是示例总是在一个只询问用户输入的程序的上下文中......并且它们总能工作但是从来没有任何节点问题. js继续到下一行代码,因为没有.
我必须得到用户输入,然后验证输入是否有效,所以我创建了这个构造:
while ( designAppealTest(subject) == false ) {
subject[DESIGN_APPEAL] = ei.errorInput('designAppeal for the subject', iteration, subject[DESIGN_APPEAL])
}
Run Code Online (Sandbox Code Playgroud)
它调用的函数是:
module.exports.errorInput = function (fieldName, iteration, originalValue) {
originalValue = originalValue || 'false'
console.log('\n\n' + fieldName + ' for the subject' + ' contains an invalid value in for #' + i)
if (originalValue !== false)
console.log('original value of field = ' + originalValue)
console.log('\nPlease enter a new value for it:\n')
process.stdin.on('data', function (text) {
console.log('received data:', text);
return text;
}); …
Run Code Online (Sandbox Code Playgroud) 我是 Android 新手,不知道如何将按钮动态添加到预先存在的布局中。我将我从关于 SO 的另一个问题中找到的一些示例代码拼凑到一个 hello world 默认项目中。
onCreate 方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button myButton = new Button(this);
myButton.setText("Add Me");
RelativeLayout ll = (RelativeLayout)findViewById(R.id.main_layout);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
ll.addView(myButton, lp);
setContentView(R.layout.activity_main);
}
Run Code Online (Sandbox Code Playgroud)
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:id="@+id/main_layout"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/cat_1"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="26dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/cat_2"
android:layout_alignBottom="@+id/cat_1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="65dp"
android:layout_marginEnd="65dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我注释掉添加按钮部分时,该项目有效,所以我知道这就是问题所在。我会粘贴一些调试信息,但 logcat 的“调试”过滤器非常冗长,即使程序没有运行也会不断更新。当我在调试模式下运行它时,手机在出现“应用程序已停止工作”消息之前显示错误几分之一秒。
我尝试使用这个结构:
function messageTest(data2, data1, value){
(!value) ? if (data2 == 0x7F) return true :
if (data1 == value && data2 == 0x7F) return false;
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了语法错误.您可以像这样单独使用三元运算符吗?我也在使用WSH执行此操作.
我已经读过,当python评估一个条件时,if x:
就会被翻译成类似的东西if bool(x):
.为什么我会看到很多bool()
直接调用的代码?这主要是为了可读性还是有其他优势?
android ×3
java ×3
javascript ×2
node.js ×2
python ×2
archlinux ×1
boolean ×1
button ×1
cheerio ×1
click ×1
dynamic ×1
eclipse ×1
html ×1
java-8 ×1
java-stream ×1
jquery ×1
lambda ×1
local ×1
pageload ×1
parcelable ×1
phantomjs ×1
python-2.5 ×1
raise ×1
synchronous ×1
tmux ×1
truthiness ×1
user-input ×1
wait ×1