我正在尝试为美国的大学和学院解析数据库的html页面.我写的代码确实提取了大学的名称,但我无法获取他们各自的网址.
public function fetch_universities()
{
$url = "http://www.utexas.edu/world/univ/alpha/";
$dom = new DOMDocument();
$html = $dom->loadHTMLFile($url);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
$tr = $tables->item(1)->getElementsByTagName('tr');
$td = $tr->item(7)->getElementsByTagName('td');
$rows = $td->item(0)->getElementsByTagName('li');
$count = 0;
foreach ($rows as $row)
{
$count++;
$cols = $row->getElementsByTagName('a');
echo "$count:".$cols->item(0)->nodeValue. "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
这是我目前的代码.
请告诉我如何获取属性值.
谢谢
附加规则:
1.程序应从标准输入读取并写入标准输出.
2.程序应该向调用系统/程序返回零.
3.程序应该使用gcc -O2 -lm -s -fomit-frame-pointer编译和运行.
挑战有一些历史:2009年9月在波兰编程竞赛博客上宣布了短期实施的要求.比赛结束后,最短的代码是81个字符长.后来第二次调用甚至更短的代码,并在年后matix2267 以78字节发布了他的解决方案:
main(c){read(0,&c,1)?c-41&&main(c-40&&(c%96<27||main(c),putchar(c))):exit(0);}
Run Code Online (Sandbox Code Playgroud)
有人让它更短或证明这是不可能的吗?
PLINQ是否保证按照正在操作的原始序列的顺序返回查询结果,即使结果是并行产生的?例如:
new List<String>(){"a", "b", "c", "d"}.asParallel().Select(str => str + "a").asSequential().ToList().ForEach(str => Console.Write(str + ", ");
Run Code Online (Sandbox Code Playgroud)
结果总是"aa,ba,ca,da"吗?
在界面中我有这个:
Animal* myPet;
Run Code Online (Sandbox Code Playgroud)
在运行时我可能希望myPet是一只猫或一只狗,它们是Animal的子类:
id newPet;
if(someCondition) {
newPet = [[Cat alloc] initWithNibName:@"Cat" bundle:nil];
} else {
newPet = [[Dog alloc] initWithNibName:@"Dog" bundle:nil];
}
self.myPet = newPet;
Run Code Online (Sandbox Code Playgroud)
显然这是不正确的,但我希望它足以显示我正在尝试做的事情.这样做的最佳做法是什么?
我需要从1到9的随机数(不含0).
//numbers 0 to 9
int iRand = rand() % 10;
Run Code Online (Sandbox Code Playgroud)
但我需要1到9岁.
谢谢.
我有一个包含Silverlight 4和WPF 4解决方案的解决方案.一个是应用程序的Web版本,一个是桌面版本.
这两个项目都有类似的域类和接口,都可以访问云存储和其他东西.
我想创建一个通用的Interfaces和Classes项目,所以我创建了一个类库,但是你不知道它,Silverlight不能添加对类库的引用.所以我创建了一个公共项目作为Silverlight类库,但是当我从WPF项目中引用它时,我收到警告:
Warning The project 'Interface.Common.Silverlight' cannot be referenced. The referenced project is targeted to a different framework family (Silverlight)
当我使用该库中的任何类时,我甚至得到类加载运行时错误,因为"在运行时找不到System.Windows"
我想在两个项目之间共享代码,如何以一种干净的方式实现这一目标?
谢谢你提供的所有帮助
是否有类似于基于 Eclipse 的 Visual SCXML 编辑器来构建 Harel 状态表的工具?目前项目页面中的状态是代码未发布。我如何安装插件?
我有一些模型的创建语句,但它在连接表中创建一条记录,无论该记录是否已存在.
这是我的代码的样子:
@user = User.find(current_user)
@event = Event.find(params[:id])
for interest in @event.interests
@user.choices.create(:interest => interest, :score => 4)
end
Run Code Online (Sandbox Code Playgroud)
问题是无论如何都会创建记录.我希望只有在没有记录的情况下才创建记录; 如果记录确实存在,我希望它获取找到的记录的属性并加1或减1.
我一直在环顾四周看过一些叫做的东西find_or_create_by.当它找到记录时这会做什么?我希望它采用当前:score属性并添加1.
是否有可能找到或创建id?我不确定我会找到什么属性,因为我正在查看的模型是一个只有id外键和得分属性的连接模型.
我试过了
@user.choices.find_or_create_by_user(:user => @user.id, :interest => interest, :score => 4)
Run Code Online (Sandbox Code Playgroud)
但得到了
未定义的方法
find_by_user
我该怎么办?
我有一个Entity Framework生成的类,具有以下属性:
public DateTime LaunchDate;
public DateTime ExpirationDate;
Run Code Online (Sandbox Code Playgroud)
我需要强制执行ExpirationDate> LaunchDate.
我正在使用各种帖子中描述的好友类.我将自定义验证属性(在属性上)应用于同一伙伴类中的其他属性,这些属性正在运行.
因为我需要比较两个属性,我直接在类上使用属性(AttributeTargets.Class)
这是我的自定义验证属性:
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class PropertyMustBeGreaterThanAttribute : ValidationAttribute
{
private const string _defaultErrorMessage = "'{0}' must be greater than '{1}'!";
public PropertyMustBeGreaterThanAttribute(string property, string greaterThan)
: base(_defaultErrorMessage)
{
GreaterThan = greaterThan;
Property = property;
}
public string Property { get; private set; }
public string GreaterThan { get; private set; }
public override string FormatErrorMessage(string name)
{
return String.Format(CultureInfo.CurrentUICulture, ErrorMessageString,
GreaterThan, Property);
} …Run Code Online (Sandbox Code Playgroud) c# ×2
asp.net-mvc ×1
c ×1
c++ ×1
class ×1
code-sharing ×1
dom ×1
html-parsing ×1
objective-c ×1
parsing ×1
php ×1
plinq ×1
regex ×1
runtime ×1
scxml ×1
security ×1
silverlight ×1
wpf ×1
xml ×1
xss ×1