我的python应用程序在几个小时的工作中使用Selenium Webdriver加载网页总共20000页.我的问题是"某些东西"正在创建大量的tmp文件,填满了我的所有硬盘.例如,今天早上应用程序在6小时的工作中生成70GB的tmp文件:(重启Ubuntu后,所有这些文件都消失了.我认为负责的是Firefox.
这种情况在Linux和OS X上都会发生.
def launchSelenium (url):
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "127.0.0.1")
profile.set_preference("network.proxy.http_port", 8080)
profile.set_preference("webdriver.load.strategy", "fast")
profile.set_preference("permissions.default.stylesheet", 2)
profile.set_preference("permissions.default.images", 2)
profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so", "false")
profile.set_preference("browser.sessionstore.enabled", "false")
profile.set_preference("browser.cache.disk.enable", "false")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get(url)
try:
element = driver.find_element_by_xpath("//button[@title='Statistics']").click()
except NoSuchElementException:
print "Not available"
driver.close()
return 0
driver.close()
return 1
Run Code Online (Sandbox Code Playgroud)
我在Firefox Profile中添加了最后两个首选项,试图解决这个问题,但没有任何改变.
难道我做错了什么?Selenium有一个错误?谢谢
我成功将我的应用添加到Android图库的"分享"按钮中,因此如果我点击它,我的应用就会启动.我可以选择启动应用的哪个活动吗?现在它开始了"主要".这是我在主类中的代码:
.....
Intent intent = getIntent();
Bundle extras = intent.getExtras();
String action = intent.getAction();
// if this is from the share menu
if (Intent.ACTION_SEND.equals(action)) {
if (extras.containsKey(Intent.EXTRA_STREAM)) {
// Get resource path
}
}
Run Code Online (Sandbox Code Playgroud)
并且清单:
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
实际上,我在"主要"开始后立即开始了一项新活动,但我更愿意直接打开正确的活动.谢谢
如果文件成功下载,我必须更新片段中的列表视图.所以在我的下载管理器的BroadcastReceiver中,我注册了这个新的广播接收器:
Intent intent = new Intent();
intent.setAction("CONTENTS_NOTIFICATION");
context.sendBroadcast(intent);
Run Code Online (Sandbox Code Playgroud)
在onCreateView的片段中,我添加以下代码以注册接收器:
IntentFilter filter = new IntentFilter("CONTENTS_NOTIFICATION");
getActivity().getApplicationContext().registerReceiver(myReceiver, filter);
Run Code Online (Sandbox Code Playgroud)
然后:
private BroadcastReceiver myReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
SQLiteDatabase db = DatabaseManager.getInstance(getActivity()).getWritableDatabase();
c = SelectedExperience.getSelectedExperiences(db);
String id_esperienza = "Selected Experience";
if (c.getCount() != 0) {
id_esperienza = c.getString(c.getColumnIndex(SelectedExperience.ID_ESPERIENZA));
}
populateListview(v, id_esperienza);
}
};
Run Code Online (Sandbox Code Playgroud)
最后:
public void onDestroyView() {
super.onDestroyView();
getActivity().getApplicationContext().unregisterReceiver(myReceiver);
}
Run Code Online (Sandbox Code Playgroud)
我必须为两个不同的片段添加两个这样的广播接收器.在第一个,一切正常.如果在应用程序中用户在片段上,它会更新,而在第二个片段上我得到了这些错误:
03-15 07:32:40.474: E/AndroidRuntime(1692): FATAL EXCEPTION: main
03-15 07:32:40.474: E/AndroidRuntime(1692): java.lang.RuntimeException: Error receiving broadcast Intent …Run Code Online (Sandbox Code Playgroud) 在我的软件中,我必须以串行方式读取多个txt数据库,所以我先阅读第一个,然后我使用从该文件获得的信息做一些事情,而不是打开另一个写入等等.
有时我在打开或创建文件时出错,然后我在以下所有打开/创建时出错,它使用不同的函数,不同的变量,不同的文件.
所以例如我调用下面的函数,它使用两个文件,我得到一个错误"*打开文件时出错 - %s- .. \n",然后我的代码中的所有其他fopen()出错了!
这是一个单个文件的代码示例:
FILE *filea;
if((filea=fopen(databaseTmp, "rb"))==NULL) {
printf("* error while opening file -%s- ..\n",databaseTmp);
fclose (filea);
printf("---------- createDatabaseBackup ----------\n");
return -1;
}
int emptyFolder=1;
FILE *fileb;
if((fileb=fopen(databaseBackup, "ab"))==NULL) {
printf("* error while opening file -%s- ..\n",databaseBackup);
fclose (fileb);
printf("---------- createDatabaseBackup ----------\n");
return -1;
}
else {
int i=0;
char c[500]="";
for (i=0;fgets(c,500,filea);i++) {
fprintf(fileb,"%s",c);
emptyFolder=0;
}
}
fclose(fileb);
fclose(filea);
Run Code Online (Sandbox Code Playgroud) 我已经成功地在我的设备上使用指定的SSID创建了一个可移植的热点.现在我想从另一台设备连接到它!我正在使用此代码:
WifiConfiguration conf = new WifiConfiguration();
conf.SSID = "\"" + "TinyBox" + "\"";
conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
wifiManager.addNetwork(conf);
List<WifiConfiguration> list = wifiManager.getConfiguredNetworks();
for( WifiConfiguration i : list ) {
if(i.SSID != null && i.SSID.equals("\"" + "TinyBox" + "\"")) {
wifiManager.disconnect();
wifiManager.enableNetwork(i.networkId, true);
wifiManager.reconnect();
break;
}
}
Run Code Online (Sandbox Code Playgroud)
但没有任何反应.哪里出错了?谢谢
我使用 spring MVC 构建了一个 Web 应用程序,除了文件上传时出现随机 FileNotFoundExceptions 之外,一切正常。我在网上找到了一些解决方案,例如使用不同的 tmp 文件夹,但我不断收到随机错误。
我的代码是:
@RequestMapping(value="/upload", method=RequestMethod.POST)
public @ResponseBody String handleFileUpload(@RequestParam("file") final MultipartFile multipartFile,
@RequestHeader("email") final String email, @RequestHeader("password") String password){
if (authenticateUser(email, password)) {
if (!multipartFile.isEmpty()) {
System.out.println("Start processing");
Thread thread = new Thread(){
public void run(){
ProcessCSV obj = new ProcessCSV();
try {
File file = multipartToFile(multipartFile);
if(file !=null) {
obj.extractEvents(file, email, cluster, session);
}
else {
System.out.println("null File");
}
} catch (IOException e) {
System.out.println("File conversion error");
e.printStackTrace();
}
}
}; …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的应用程序中创建一个NSMenu.我成功地创建了一些固定项目的菜单,现在我必须以编程方式添加一些项目.我也成功了,但它将项目添加到其他项目的底部.有一种方法可以将这个以编程方式创建的项目放在固定项目之间吗?这是我的代码:
.H:
@interface AppController : NSObject {
IBOutlet NSMenu *statusMenu;
NSStatusItem *statusItem;
}
Run Code Online (Sandbox Code Playgroud)
.M
[statusMenu setAutoenablesItems:NO];
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setMenu:statusMenu];
NSImage *statusImage = [[NSImage alloc] initWithContentsOfFile:@"Icon.icns"];
[statusItem setImage:statusImage];
[statusItem setTitle:@"Multibox"];
[statusItem setHighlightMode:YES];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:@"Carlo | 0000000000"
action:@selector(fooClicked:) keyEquivalent:@""];
[item setTarget:self];
[statusMenu addItem:item];
Run Code Online (Sandbox Code Playgroud) 我的程序中有很多数组都有这个问题,我无法理解为什么.我想我对阵列理论有所遗漏.
"有人"在我的数组的末尾添加了某些字符,例如?^)(&%.例如,如果我有一个带有"hello"的长度为5的数组,那么它已经满了,有时会打印你好?() /&%%.如果它只有5个元素并且我只使用5个,那么它可能会发生意外,所以也许其他5个元素会得到一些随机值,但如果它已满,那么地狱会得到那些奇怪的值?
我通过manaully添加字符'\ 0'来部分解决它.
例如,当我尝试从另一个数组填充数组时,会出现此问题(我从fgets读取一行测试文件,然后我必须提取单个单词):
...
for(x=0;fgets(c,500,fileb);x++) { // read old local file
int l=strlen(c);
i=0;
for (k=0;k<(l-34);k++) {
if(c[k+33]!='\n') {
userDatabaseLocalPath[k]=c[k+33];
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我是 SQLite 的新手。我使用此查询是为了从特定用户的列中提取所有行:
Cursor c = db.query(true, TABLE, COLUMN, USER + "= '" + user + "'", null, null, null, null, null);
Run Code Online (Sandbox Code Playgroud)
这是表的示例:
|group-----ID|
|------------|
|one-------me|
|one------you|
|two-------me|
|one-------me|
Run Code Online (Sandbox Code Playgroud)
所以用户“我”的查询提取“一,二,一”。如何过滤结果以便仅获得一次值?比如“一、二”
谢谢
我有一个文件对象List我想根据类型学(音频,视频,照片)或捕获日期/时间或Exif信息(如果是照片)等一些规则进行过滤.我可以用一些例如cicles来做.
有一种聪明的方法吗?我在某地读到解决方案可能是使用Google Guava的Predicates,但我无法理解它是如何工作的.有什么建议吗?谢谢
我创建了一个单例类,以便在我的程序中共享一个对象.这是代码:
SelectedRow.h
#import <Foundation/Foundation.h>
#import "TableEntry.h"
@interface SelectedRow : NSObject {
TableEntry *rowValue;
}
@property (nonatomic, retain) TableEntry *rowValue;
+ (id)sharedManager;
- (void)setVariable:(TableEntry*)value;
@end
Run Code Online (Sandbox Code Playgroud)
和SelectedRow.m
#import "SelectedRow.h"
#import "TableEntry.h"
@implementation SelectedRow
@synthesize rowValue;
+ (id)sharedManager {
static SelectedRow *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
rowValue = [[TableEntry alloc] init];
}
return self;
}
- (void)setVariable:(TableEntry*)value {
rowValue = value;
} …Run Code Online (Sandbox Code Playgroud) 我在python中有以下脚本,每隔X秒调用一个函数来创建一个新线程:
def function():
threading.Timer(X, function).start()
do_something
function()
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果函数需要2 * X秒执行怎么办?由于我正在使用线程,这应该不是问题,对吧?我将同时运行该函数的更多“实例”,但是一旦每个实例完成,其线程都应该被销毁。谢谢