Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntitySpider ,一对多的关系怎么处理呢? #50

Closed
xiaoyc opened this issue Apr 10, 2018 · 2 comments
Closed

EntitySpider ,一对多的关系怎么处理呢? #50

xiaoyc opened this issue Apr 10, 2018 · 2 comments

Comments

@xiaoyc
Copy link

xiaoyc commented Apr 10, 2018

请问 假如一篇文章有多个作者,每个作者对应一张图片, 在entitysipder 里面改如何定义字段类型呢?

现在Demo 里面好像都是单一的类型。
[PropertyDefine(Expression = ".//div[@Class='p-name']/a/em", Length = 100)]
public string Name { get; set; }

能实现类似的么?
[PropertyDefine(Expression = ".//div[@Class='p-name']/a/em", Length = 100)]
public List‘<string’> Name { get; set; }

或者给 每个字段解析成功后能定义个callback 函数也行。
谢谢!

@zlzforever
Copy link
Collaborator

List 这种解析最早是支持的,只是数据库只有在Mongo才能存这种数据,后来为了简洁就去掉了。你这种其实可以这样实现

	[EntityTable("test", "image")]
	[EntitySelector(Expression = "//...//img")]
	class Images : SpiderEntity
	{
		[PropertyDefine(Expression = "./@src", Length = 500)]
		public string src { get; set; }

		[PropertyDefine(Expression = "../../ 相对当前节点往上的XPATH写法", Length = 100)]
		public string author { get; set; }
	}

如果不行,则建议你自己实现一个BasePageProcessor

@xiaoyc
Copy link
Author

xiaoyc commented Apr 10, 2018

非常感谢。

@xiaoyc xiaoyc closed this as completed Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants