当前位置:网站首页>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());
边栏推荐
- C语言学生信息管理系统
- Glitch Free时钟切换技术
- 通过 代码实例 理解 浅复制 与 深复制
- I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
- Dynamic proxy
- Ape anthropology topic 20 (the topic will be updated from time to time)
- Public network cluster intercom +gps visual tracking | help the logistics industry with intelligent management and scheduling
- 动态代理
- 截图小妙招
- What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
猜你喜欢
3、Modbus通讯协议详解
5mo3 UHI HII HII 17mn4 19Mn6 executive standard
安装Oracle EE
How to manage fixed assets well? Easy to point and move to provide intelligent solutions
MD文档中插入数学公式,Typora中插入数学公式
Nacos - gestion de la configuration
Pain points and solutions of equipment management in large factories
Redis -- lattice connects to redis cluster
Jetson nano installs tensorflow GPU and problem solving
Advanced level of C language pointer (Part 1)
随机推荐
Bimianhongfu queren()
[untitled]
Embedded Engineer Interview Question 3 Hardware
截图小妙招
Interrupt sharing variables with other functions and protection of critical resources
Daily office consumables management solution
In depth learning training sample amplification and tag name modification
Shell脚本-变量的定义、赋值和删除
What are the differences between the architecture a, R and m of arm V7, and in which fields are they applied?
TypeError: __ init__ () got an unexpected keyword argument ‘autocompletion‘
Understand shallow replication and deep replication through code examples
pcl_ Viewer command
Embedded Engineer Interview frequently asked questions
美团2022年机试
Foundation: 3 Opencv getting started images and videos
钓鱼识别app
Yidian Yidong helps enterprises to efficiently manage equipment and improve equipment utilization
Mysql 优化
Shell script case in statement
目标检测的yolov3、4、5、6总结