当前位置:网站首页>Summary of reptile knowledge points
Summary of reptile knowledge points
2022-07-01 08:57:00 【hellolianhua】
One , Get the html file
Use webClient Get web information , This method passes in url You can get html String
public static string HttpPost(string url, string paraJsonStr)
{
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] postData = System.Text.Encoding.UTF8.GetBytes(paraJsonStr);
byte[] responseData = webClient.UploadData(url, "POST", postData);
string returnStr = System.Text.Encoding.UTF8.GetString(responseData);
return returnStr;
}Two , Regular matching
MatchCollection matches = Regex.Matches(str, @">(.*)</h1>");
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
//group[1] It's the content
Console.WriteLine(groups[1].Value);
}The dictionary form
Dictionary<string, string> resultDict = new Dictionary<string, string>();
foreach (Match matchedGroup in Regex.Matches(str, @"<p>(?<key>.*)</p>\n<ul>\n(?<value>[\w\W\n]*?)</ul>"))
{
Console.WriteLine(matchedGroup.Groups["key"].Value);
if (matchedGroup.Groups["key"].Value.Contains("hahhaha"))
{
resultDict.Add(matchedGroup.Groups["key"].Value, matchedGroup.Groups["value"].Value);
}
}3、 ... and , write file
write in txt file
using (StreamWriter sw = new StreamWriter($"C:\\hhaha.txt"))
{
resultDict.ToList().ForEach(x => { sw.WriteLine($"{x.Key}"); sw.WriteLine($"{x.Value}"); });
}
write in csv file , among new StreamWriter($" route ",true) This true It means that the existing file should not be created , This file does not exist , You need to create this file
using (StreamWriter sw = new StreamWriter($"C:\\Users\\haha1.CSV", true))
{
if (type == "people")
{
sw.WriteLine("name," + name);
//aValue It's a list, There are commas that jump to multiple columns
aValue.ToList().ForEach(x => { sw.WriteLine("hobby," + (x)); });
}else if(type== "animals")
{
sValue.ToList().ForEach(x => { sw.WriteLine(" looks ," + (x)); });
sw.WriteLine("");
}
else
{
}
}This adds a new line to the file
//File.AppendAllLines($"C:\\Users\\hobby.CSV", Value.ToArray());
边栏推荐
- Embedded Engineer Interview Question 3 Hardware
- Promise asynchronous programming
- Serialization, listening, custom annotation
- [untitled]
- Foundation: 3 Opencv getting started images and videos
- Nacos - gestion de la configuration
- R language observation log (part24) -- initialization settings
- Shell脚本-位置参数(命令行参数)
- 如何做好固定资产管理?易点易动提供智能化方案
- C语言指针的进阶(上篇)
猜你喜欢

Advanced level of C language pointer (Part 1)

Matlab tips (16) consistency verification of matrix eigenvector eigenvalue solution -- analytic hierarchy process

小鸟识别APP

如何解决固定资产管理和盘点的难题?

性能提升2-3倍!百度智能云第二代昆仑芯服务器上线

C语言指针的进阶(上篇)

Brief introduction to AES

1.jetson与摄像头的对接

Jetson Nano 安装TensorFlow GPU及问题解决

"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
随机推荐
你了解数据是如何存储的吗?(C整型和浮点型两类)
集团公司固定资产管理的痛点和解决方案
Glitch Free时钟切换技术
Jetson nano installs tensorflow GPU and problem solving
Foundation: 3 Opencv getting started images and videos
钓鱼识别app
猿人学第20题(题目会不定时更新)
Pain points and solutions of fixed assets management of group companies
Jeecg restart alarm 40001
Shell script - definition, assignment and deletion of variables
Which method is good for the management of fixed assets of small and medium-sized enterprises?
通过 代码实例 理解 浅复制 与 深复制
factory type_ Id:: create process resolution
FreeRTOS学习简易笔记
动态代理
pcl_viewer命令
C语言指针的进阶(上篇)
Shell script - string
"Analysis of 43 cases of MATLAB neural network": Chapter 30 design of combined classifier based on random forest idea - breast cancer diagnosis
Shell脚本-位置参数(命令行参数)