我现在用的LWP::UserAgent
,
HTML::Selector::XPath
和
HTML::TreeBuilder::XPath
模块获得的值href
第一的YouTube视频在一组搜索结果的属性.
到目前为止我的代码是:
use LWP::UserAgent;
use HTML::TreeBuilder::XPath;
use HTML::Selector::XPath;
my $ua = LWP::UserAgent->new;
#my $response =..
my $html = "http://www.youtube.com/results?search_query=run+flo+rida";
my $tree = HTML::TreeBuilder::XPath->new;
my $xpath = HTML::Selector::XPath::selector_to_xpath("(//*[@id = 'search-results']/li)[1]/div[2]/h3/a/@href/");
my @nodes = $tree->findnodes($xpath);
print" $nodes[0]";
Run Code Online (Sandbox Code Playgroud)
如果其他语法错误,我不确定我的打印是否不正确.截至目前,它打印
HTML::TreeBuilder::XPath=HASH(0x1a78250)
Run Code Online (Sandbox Code Playgroud)
当我正在寻找它打印
/watch?v=JP68g3SYObU
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我正在尝试为fetchall_arrayref中的每个值执行一个foreach循环,并且遇到了一些麻烦.
我有:
my $list = $sth->fetchall_arrayref({});
print Dumper($list);
Run Code Online (Sandbox Code Playgroud)
这给了我:
$VAR1 = [
{
'ID_NUMBER' => '123'
},
{
'ID_NUMBER' => '456'
},
{
'ID_NUMBER' => '5666'
},
{
'ID_NUMBER' => '45645'
},
{
'ID_NUMBER' => '23422'
}
];
Run Code Online (Sandbox Code Playgroud)
我不知道如何格式化我的foreach循环打印每个id_number的值.最终我想用每个值运行一个查询,但是一旦我开始工作,我就可以想出来.
谢谢你的帮助.
我有一个具有多个属性的类,希望将其排序。目前,我正在Name
像这样排序:
Collections.sort(rowItems, new Comparator() {
public int compare(Object o1, Object o2) {
SearchRowItem p1 = (SearchRowItem) o1;
SearchRowItem p2 = (SearchRowItem) o2;
return p1.getName().compareToIgnoreCase(p2.getName());
}
});
Run Code Online (Sandbox Code Playgroud)
但我也想排序LastName
其次为Name
(所以如果名称相同,排序LastName
第二)。如何将下面的代码与第一类代码结合起来以得到我描述的结果?
Collections.sort(rowItems, new Comparator() {
public int compare(Object o1, Object o2) {
SearchRowItem p1 = (SearchRowItem) o1;
SearchRowItem p2 = (SearchRowItem) o2;
return p1.getLastName().compareToIgnoreCase(p2.getLastName());
}
});
Run Code Online (Sandbox Code Playgroud) 我需要用我在目标C中存储的变量填充html webview.
我相信我需要使用:
[self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"John", firstName];
Run Code Online (Sandbox Code Playgroud)
但不知道放在那里以及我的javascript需要实现传递的变量.
这里有一点我的html来帮助你了解一下:
<ul><li><span>First Name:</span> first name needs to go here</li>
<li><span>Last Name:</span> last name needs to go here</li>
Run Code Online (Sandbox Code Playgroud)
更新的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"idcard" ofType:@"html"]isDirectory:NO]]];
}
-(void)viewDidAppear:(BOOL)animated
{
NSString *str = @"John";
NSString *script = [NSString stringWithFormat:@"myFunc('%@')", str];
[self.webView stringByEvaluatingJavaScriptFromString:script];
}
Run Code Online (Sandbox Code Playgroud)
更新2: javascript/html:
<ul><li><span>Policy Number:</span>
<script> function myFunc(str)
{
document.write(str) }
</script>
Run Code Online (Sandbox Code Playgroud) 我正在尝试将字母转换为字母表中各自的数字.我有一个哈希,我认为应该工作我只是不知道如何将它应用于我的字符串.
串:
my $string = "abc";
Run Code Online (Sandbox Code Playgroud)
和我的哈希:
@hash{("a".."z")} = (1..26);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何让我的字符串为123?
我是阻止的新手,我试图弄清楚如何在执行我的操作之前等待块完成(在这种情况下是一个nslog)所以我怎么能等到块完成之后再执行以下代码中的这个nslog: NSLog(@"convertedPhotos::%@",convertedImages);
convertedImages = [[NSMutableArray alloc] init];
for (NSDictionary *photo in photos) {
// photo is a dictionary containing a "caption" and a "urlRep"
[photoUrls addObject:photo[@"urlRep"]];
}
if (photoUrls.count) {
for (id photos in photoUrls){
NSString *urlString = photos;
[self base64ImageAtUrlString:urlString result:^(NSString *base64) {
[jsonWithPhotos setObject:convertedImages forKey:@"photo64"];
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonWithPhotos
options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string
error:&error];
if (! jsonData) {
NSLog(@"Got an error: %@", error);
} …
Run Code Online (Sandbox Code Playgroud) 我对 java 和 android 有基本的了解,但我仍然是新手,正在努力寻找保存变量并能够从其他类/活动访问/读取它的正确方法。我见过单例,但我很困惑这是否是正确的方式以及它的外观,我还需要确保它的线程安全吗?
有没有我不知道的更好的方法?
基本上我有一个登录名,可以获取用户名和有关该用户的一些信息。我如何将其保存到类/单例中并稍后访问它?
编辑
经过更多搜索后,我发现了这个例子:
public class Drivers {
private static Array drivers;
public static void setDrivers(Array c){
drivers = c;
}
public static Array getDrivers(){
return drivers;
}
}
Run Code Online (Sandbox Code Playgroud)
并像这样获取和设置:
public class AnyClass {
{
int clicks = ActionClass.getDrivers();
ActionClass.setDrivers(0);
}
Run Code Online (Sandbox Code Playgroud)
这有效/正确吗?
我试图从应用程序委托弹出到导航堆栈的根视图控制器,并有一些问题将obj-c中的工作转换为swift.
什么在obj-c中有效:
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
[navigationController popToRootViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
我转换的尝试:
var navigationController: UINavigationController = self.window?.rootViewController;
navigationController.popToRootViewControllerAnimated(true);
Run Code Online (Sandbox Code Playgroud)
我得到一个错误说UIViewController?不能转换为UINavigationController'
我怎样才能解决这个问题?
这是我的代码:
$STH1000=$DBH->query("CREATE TABLE IF NOT EXISTS '".$dept.$year."' ( `ID` INT( 255 ) NOT NULL AUTO_INCREMENT , `URL` VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `ID` )) ")
or die "Could not prepare sql statement";
我想要做的就是创建一个表,如果$ dept $ year不存在,但我现在拥有它的方式,它会抛出错误.
我相信有一种方法来创建一个表是mysql在select上返回一个错误,但我不知道怎么做.任何帮助将不胜感激.
我不确定我在这里做错了什么.
json(响应):
Response: {"success":true,"message":"Registration Success, check your email to validate your account so you can login"}
Run Code Online (Sandbox Code Playgroud)
我的代码:
console.log("Response: "+response);
obj = JSON.parse(response);
alert(obj.success);
if (obj.success == 'true')
{
console.log("Response:success detected ");
alert('hi');
}
Run Code Online (Sandbox Code Playgroud)
即使alert(obj.success)给我一个'true'警告,我也永远不会进入if语句.是什么让我的if语句不正常?
perl ×4
ios ×3
java ×2
javascript ×2
objective-c ×2
android ×1
comparator ×1
dbi ×1
hash ×1
iphone ×1
json ×1
mysql ×1
sorting ×1
swift ×1
xpath ×1