Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除页面主页面之前的内容_C#_String_Main_Ignore_Remove - Fatal编程技术网

C# 删除页面主页面之前的内容

C# 删除页面主页面之前的内容,c#,string,main,ignore,remove,C#,String,Main,Ignore,Remove,我正在用c#创建一个自动测试来搜索页面中的字符串,这些字符串大部分是HREF,但我只希望搜索main,而不是页面标题 //Create a StreamReader to read the response StreamReader readStream; if (response.CharacterSet == null) { readStream = new St

我正在用c#创建一个自动测试来搜索页面中的字符串,这些字符串大部分是HREF,但我只希望搜索main,而不是页面标题

            //Create a StreamReader to read the response
            StreamReader readStream;

            if (response.CharacterSet == null)
            {
                readStream = new StreamReader(response.GetResponseStream());
            }
            else
            { 
            
                readStream = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(response.CharacterSet));
            }

            //Read the response (page source)
            string data = readStream.ReadToEnd();

这是我目前正在使用的代码,但它也是从标题中提取出来的,我想忽略删除

您是否尝试过类似的简单方法(假设:


StreamReader readStream;
if(response.CharacterSet==null)
readStream=newstreamreader(response.GetResponseStream());
其他的
readStream=newstreamreader(response.GetResponseStream(),Encoding.GetEncoding(response.CharacterSet));
//读取响应(页面源)
字符串dataBody=null;
而(!readStream.EndOfStream)
{
string line=readStream.ReadLine();
bool isPageHeader=CheckIsHeader(行);
如果(!isPageHeader)
{ 
dataBody=line+readStream.ReadToEnd();
打破
}
}

实际上,这只是将您的问题转移到编程函数
CheckIsHeader(line);
。但希望这是您可以管理所有正在分析的页面类型的东西

您需要为标识“main”的元素解析流您所指的html。我可能还建议研究Selenium作为一种更容易找到元素的解决方案:我尝试使用此方法处理CheckIsHeader(line);
private static bool CheckIsHeader(string line){throw new NotImplementedException();}
但它会抛出大量错误有没有其他方法可以应用类似的内容?当然,您必须实现自己的代码来检测行是否是标头的一部分或不在该方法内(并明显删除默认的
throw new NotImplementedException();
)。也许你可以用你想分析的页面类型和标题的一般格式来完成你的文章。