// 通过节点名称以及节点的一个属性值在源码中过滤出相应的信息
public NodeList getNodeListByAttribute(string nodeName, string attributeName, string attributeValue, Parser paser)
{
NodeFilter nodeFilter = new TagNameFilter(nodeName);
NodeFilter nameFilter = new HasAttributeFilter(attributeName, attributeValue);
AndFilter andFilter = new AndFilter(nodeFilter, nameFilter);
NodeList nodeList = paser.ExtractAllNodesThatMatch(andFilter);
return nodeList;
}
// urlParam 网址,返回网页源代码
public string GetStringByResponse(string urlParam, string coding)
{
if (coding.Length == 0) // 如果传过来的编码类型为空 则默认为 UTF-8
coding = "UTF-8";
WebRequest request; // 实例一个请求对象
try
{
request = WebRequest.Create(urlParam); // 创建一个参数为下载页面的请求
}
catch (UriFormatException)
{
request = null;
}
request.Credentials = CredentialCache.DefaultCredentials; // 若服务器需要,则设置凭据
HttpWebResponse response = null; // 设置响应为null
Stream dataStream = null; // 设置服务器端的响应流为null
StreamReader reader = null;
string responseFromServer = null; // 从服务器中获得响应的字符串
try
{
response = (HttpWebResponse)request.GetResponse(); // 获得响应
if (response.StatusCode == HttpStatusCode.OK) // 请求成功
{
dataStream = response.GetResponseStream(); // 从响应中获得响应的流信息
reader = new StreamReader(dataStream, Encoding.GetEncoding(coding));
responseFromServer = reader.ReadToEnd(); // 从streamReader中读出响应流string,得出相应的具体内容
}
}
catch (WebException)
{
return null;
}
finally
{
if (reader != null)
reader.Close();
if (dataStream != null)
dataStream.Close();
if (response != null)
response.Close();
}
return responseFromServer; ;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
C#爬虫重要文件.rar (40个子文件)
C#爬虫重要文件
GetWeatherTest
GetWeatherTest.suo 17KB
GetWeatherTest
GetWeatherTest.csproj 2KB
bin
Debug
GetWeatherTest.exe 7KB
GetWeatherTest.pdb 16KB
GetWeatherTest.vshost.exe.manifest 490B
GetWeatherTest.vshost.exe 11KB
Winista.HtmlParser.dll 184KB
obj
x86
Debug
GetWeatherTest.exe 7KB
ResolveAssemblyReference.cache 9KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
GetWeatherTest.pdb 16KB
TempPE
GetWeatherTest.csproj.FileListAbsolute.txt 1KB
Properties
AssemblyInfo.cs 1KB
Program.cs 3KB
Winista.HtmlParser.dll 184KB
GetWeatherTest.sln 884B
GetWeatherTest.5.1.ReSharper.user 3KB
_ReSharper.GetWeatherTest
DecompilerCache
TodoCache
.version 4B
.crc 4B
6
57b83eb1.dat 251B
WebsiteFileReferences
.version 4B
.crc 4B
Resources
.version 4B
.crc 4B
BuildScriptCache
.version 4B
.crc 4B
8
7
4861887e.dat 85B
TagPrefixes
.version 4B
.crc 4B
PdbInfo
WordIndex
.version 4B
.crc 4B
6
1812259a.dat 1KB
ProjectModel
ProjectModel.dat 220B
NamedArguments
.version 4B
.crc 4B
6
1812259a.dat 394B
ModuleIds.xml 209B
SymbolCache.bin 492B
重要的Dll文件和方法
重要方法.txt 2KB
Winista.HtmlParser.dll 184KB
共 40 条
- 1
WHI
- 粉丝: 30
- 资源: 35
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页