当前位置:网站首页>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());
边栏推荐
- The fixed assets management system enables enterprises to dynamically master assets
- Insert mathematical formula in MD document and mathematical formula in typora
- Shell脚本-位置参数(命令行参数)
- Redis——Lettuce连接redis集群
- 中断与其他函数共享变量、临界资源的保护
- How to manage fixed assets efficiently in one stop?
- jeecg 重启报40001
- Promise异步编程
- What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
- 如何解决固定资产管理和盘点的难题?
猜你喜欢

Only in China! Alicloud container service enters the Forrester leader quadrant

Nacos - Configuration Management

Mysql 优化

明明设计的是高带宽,差点加工成开路?

Advanced C language pointer (Part 2)

Personal decoration notes

Computer tips

大型工厂设备管理痛点和解决方案

Redis——Lettuce连接redis集群

Ape anthropology topic 20 (the topic will be updated from time to time)
随机推荐
Flink interview questions
Memory size end
Shell脚本-echo命令 转义符
小鸟识别APP
Only in China! Alicloud container service enters the Forrester leader quadrant
Computer tips
Shell脚本-if else语句
Common interview questions for embedded engineers 2-mcu_ STM32
Introduction to 18mnmo4-5 steel plate executive standard and delivery status of 18mnmo4-5 steel plate, European standard steel plate 18mnmo4-5 fixed rolling
Input标签的type设置为number,去掉上下箭头
C语言指针的进阶(上篇)
Jeecg restart alarm 40001
如何一站式高效管理固定资产?
动态代理
yolov5训练可视化指标的含义
JCL 和 SLF4J
足球篮球体育比赛比分直播平台源码/app开发建设项目
如何解决固定资产管理和盘点的难题?
Which method is good for the management of fixed assets of small and medium-sized enterprises?
截图小妙招