我有html文件,我想将该文件的内容作为字符串值存储在变量中。我试过这个,但它返回一个空白字符串。我怎么能这样做?
AlertDialog.Builder builderSingle = new AlertDialog.Builder(DialogActivity.this);
builderSingle.setIcon(R.drawable.ic_launcher);
builderSingle.setTitle("Select One Name:-");
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
DialogActivity.this,
android.R.layout.select_dialog_singlechoice);
arrayAdapter.add("Hardik");
arrayAdapter.add("Archit");
arrayAdapter.add("Jignesh");
arrayAdapter.add("Umang");
arrayAdapter.add("Gatti");
builderSingle.setNegativeButton(
"cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderSingle.setAdapter(
arrayAdapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String strName = arrayAdapter.getItem(which);
AlertDialog.Builder builderInner = new AlertDialog.Builder(
DialogActivity.this);
builderInner.setMessage(strName);
builderInner.setTitle("Your Selected Item is");
builderInner.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
dialog.dismiss();
}
});
builderInner.show();
}
});
builderSingle.show();
答案 0 :(得分:0)
使用await browser.wait(EC.invisibilityOf(...)); // It contains parameters.
await browser.sleep(2000);
代替"""string_literal"""
或"string_literal"
。 “”“ string_literal”“”用于多行字符串。这将起作用。
'string_literal'
答案 1 :(得分:0)
奇怪,我看不到这种行为:
def get_content(path):
with open(path) as f:
raw_lines = f.readlines()
content = ''.join(raw_lines)
return content
为我提供了HTML内容。
另一方面:
-您正在覆盖str
,这是将字符串中的某些内容转换为基本的python函数。我看不到这个结局很好(意思是:我过去做过,不是很漂亮)
-无需声明变量,这是python
-我不明白为什么要阅读行然后不做任何事情就将它们加入。
我认为,这样会更好:
def get_content(path):
with open(path) as f:
raw = f.read()
return raw
答案 2 :(得分:-1)
尝试
f = open("0101.html", "r")
str1 = f.readlines()
print(str1)
f.close()