1877

Crawler – Split column

Problem

The second line contains pingying and alias.

html code: Zhōngfǔ   肺之募穴

First try get data roughly:

alias = p.Select(Selectors.XPath("//span[@style]"))?.Value.Replace(" ", " ");

Result: Zhōngfǔ   肺之募穴

Split the alias column in MySQL:

UPDATE `xuewei` set pingying=substring_index(alias,' ',1);
UPDATE `xuewei` set bieming=substring_index(alias,' ',-1);

Split the column in process:

alias = p.Select(Selectors.XPath("//span[@style]"))?.Value.Replace(" ", " ");
var arr = alias.Split(' ');
pingying = arr[0];
alias = arr[arr.Length-1];  //get last item in the array for the space in between is uncertain.

Save to database:

await conn.ExecuteAsync(
	$"INSERT IGNORE INTO xuewei (name,pingying,alias,position,anatomy,indication,operation,imagegeneral,imagepoint) VALUES " +
	$"('{data.Name}', '{data.Pingying}', '{data.Alias}', '{data.Position}', '{data.Anatomy}', '{data.Indication}', '{data.Operation}', '{data.ImageGeneral}', '{data.ImagePoint}');");

 265 total views

Author: Albert

Leave a Reply