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

CS1660 #710

Closed
nczsl opened this issue Mar 31, 2023 · 4 comments
Closed

CS1660 #710

nczsl opened this issue Mar 31, 2023 · 4 comments

Comments

@nczsl
Copy link

nczsl commented Mar 31, 2023

image
image

in .csx file appear this error

@seesharper
Copy link
Collaborator

Could you provide a repro script ?

@nczsl
Copy link
Author

nczsl commented Mar 31, 2023

#! "net7.0"
#load "./define.csx"
// #r "c:/Users/hjjls/.nuget/packages/anglesharp/1.0.1/lib/net7.0/AngleSharp.dll"
// #r "C:/Users/hjjls/.nuget/packages/anglesharp.xpath/2.0.1/lib/net6.0/AngleSharp.XPath.dll"
using System;
using System.Data;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using Synario.Interactive;
using Synario.Interactive.Generate;
using Synario.Interactive.Data;
using Synario.Interactive.Simulate;
using System.Net.Http;
using System.Threading;
using AngleSharp;
using AngleSharp.XPath;

var targetAddress = "https://zyk.99.com.cn/baike/zhongyao/";

ctx.Map.DbStoreDir = "e:/dbstore";
// create scaleph
MetaType getMtIndex()
{
var mtindex = MetaType.Build("ZhongYaoIndex", MetaTypePrefix.Res);
mtindex.AddField("href", typeof(string));
mtindex.AddField("name", typeof(string));
mtindex.AddField("group", typeof(string));
return mtindex;
}
ScalephSetting getBaseSetting()
{
var basePath = "/html/body/div[5]/div[3]/div[1]";///html/body/div[5]/div[3]/div[1]
var setting = new ScalephSetting(targetAddress, basePath);
//
setting.SubXPaths.Add("dl");
setting.SubXPaths.Add("dd");
setting.SubXPaths.Add("a");
//
setting.EncodeStr = "gb2312";
setting.GetFieldXPath = (xpath, fn) =>
{
switch (fn)
{
case "href": return $"{xpath}/@href";
case "name": return $"{xpath}/text()";
case "group": return $"{xpath}/../../dt/h2/a/text()";
}
throw new Exception("xpath not found");
};
return setting;
}
var scaleph = new Scaleph(ctx.Map.DbStoreDir);
if (!System.IO.File.Exists(scaleph.DbPath))
{
// create db
System.IO.File.Create(scaleph.DbPath).Close();
}
//
var mtindex = getMtIndex();
var setting = getBaseSetting();
async Task setMtIndex()
{
var idoc = await scaleph.GetDocumentAsync(setting);
var rows = scaleph.Extract(idoc, setting, mtindex);
foreach (var i in rows)
{
mtindex.Rows.Add(i);
}
}
await setMtIndex();
//type count
Console.WriteLine(mtindex.Rows.Count);
//
MetaType GetMetaDetail()
{
var mt = MetaType.Build("ZhongYaoDetail", MetaTypePrefix.Res);
mt.AddField("Id", Descrip.Int);
mt.AddField("Name", Descrip.String);
mt.AddField("Img", Descrip.Binary);
mt.AddField("Alias", Descrip.String);
mt.AddField("SiQi", Descrip.String);
mt.AddField("WuWei", Descrip.String);
mt.AddField("ChannelTropism", Descrip.String);//归经
mt.AddField("UsageDosage", Descrip.String);//用法用量
mt.AddField("EfficacyIndications", Descrip.String);//功效主治
mt.AddField("VariousDiscussions", Descrip.String);//各家论述
return mt;
}
ScalephSetting getDetailSetting()
{
var basePath = "/html/body/div[5]/div[2]/div[1]";
var setting = new ScalephSetting("", basePath);
setting.GetFieldXPath = (string xpath, string fn) =>
{
return "2";
// throw new Exception("xpath not found");
};
return setting;
}
async Task getZyDetail()
{
scaleph.QueryIndexTable();
var mtdetail = GetMetaDetail();
var settingdetail = getDetailSetting();
var settings = from i in SysDescriptor.Res_ScalephTemp.AsEnumerable()
select settingdetail with { url = i.Field(SysScalephTemp.baseurl) };

await foreach (var i in scaleph.GetDocumentsAsync(settings))
{
var rows = scaleph.Extract(i, settingdetail, mtdetail);
foreach (var j in rows)
{
mtdetail.Rows.Add(j);
}
}

//show mtdetail
foreach (DataRow i in mtdetail.Rows)
{
foreach (DataColumn j in mtdetail.Columns)
{
Console.WriteLine($"{j.ColumnName}:{i[j]},");
}
System.Console.WriteLine("-----------------");
}
}

Console.WriteLine("start");

@nczsl
Copy link
Author

nczsl commented Mar 31, 2023

"However, I cannot use simple code in the. csx file to demonstrate that this error occurs again. Although the code is marked with a red line, it can run successfully."

@nczsl
Copy link
Author

nczsl commented Mar 31, 2023

I have found a problem that when I add the '# load" xxx "statement, a red line error occurs. If it is not present or commented out, no red line error occurs.

@nczsl nczsl closed this as completed Oct 28, 2023
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