Giter Site home page Giter Site logo

apkeywordparser's Introduction

https://www.ap-siken.com/keyword/_y.html https://www.ap-siken.com/keyword/_z.html https://www.ap-siken.com/keyword/tu.html https://www.ap-siken.com/keyword/nu.html https://www.ap-siken.com/keyword/ne.html https://www.ap-siken.com/keyword/no.html https://www.ap-siken.com/keyword/mu.html https://www.ap-siken.com/keyword/ya.html https://www.ap-siken.com/keyword/yo.html には単語がない

実装してておもろかったとこ

TypeScriptやJavaScriptはあまり使わないので苦労した. その中でもhttpリクエストのレスポンスを処理するところが苦労した.

async function getHtml(source: string): Promise<string | undefined> {
	let response: Response = await fetch(source);

	const decoder = new TextDecoder('shift-jis');
	let output: string = "";

	var readablestream = response.body?.getReader()
	if(readablestream == undefined) return undefined;
	while(true){
		var stream = await readablestream.read();
		if(stream?.value == undefined) break;

		var resp = stream!.value;
		output += decoder.decode(resp);
		if(stream.done == true) break;
	}
	//前のコードは一つの単位分しかストリームから読み取ってなかったので,途中で結果が途切れてしまっていたみたい.

	if(output.length == 0) return undefined;
	return output;
	
//	await response.then(
//		async (value) => {
//			var stream = await value.body?.getReader().read();
//			var resp = stream!.value;
//
//			if(resp == undefined) console.log("これはundefinedです");
//
//			return decoder.decode(resp);
//	});
}

fetchでリスポンスを受け取る.

そしてリスポンスからbodyを取得する必要があるが,C#ならreadAsBytesAsyncメソッドを使えば簡単にできるのにTypeScriptではストリームを処理する必要がある.

Streamからはチャンク単位(ある一定の単位)でデータを受け取ることができる.その処理がwhile文のところ

元々37-47行目の処理を使っていたが,これだと1チャンクしか読み取らないので途中までしか結果を取得できていなかった. while(true)でループ回してるのは良くないと思う

apkeywordparser's People

Contributors

tauto1127 avatar

Watchers

 avatar

apkeywordparser's Issues

説明文が複数行だと,行数分単語があると認識される.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.