简体   繁体   English

在C#中异步HTTP请求

[英]async http requests in c#

so im making a program which is kind of a web crawler. 所以我正在制作一个类似于网络爬虫的程序。 it downloads the html of a page and parses it for a specific text using regex and then adds it to a list. 它下载页面的html并使用regex解析为特定文本,然后将其添加到列表中。

to achieve this, i used async http requests. 为了达到这个目的,我使用了异步http请求。 the GET request is sent asynchronously and the parsing operation is performed on the returned html. GET请求被异步发送,并且对返回的html进行解析操作。

my issue, and i'm not sure if it may be simple, is that the program doesn't run smoothly. 我的问题是,我不确定该程序是否简单,因为该程序无法顺利运行。 it will send a bunch of requests, pause for a couple seconds, then increments the items parsed all at once (although the counter is programmed to increment once every time an item is added) so that for example it jumps from 53 to 69 instead of showing, 54,55,56,... 它会发送一堆请求,暂停几秒钟,然后一次增加所有解析的项目(尽管计数器被编程为每次添加一项都增加一次),例如,它从53跳到了69显示,54、55、56,...

sorry for being a newb but i taught myself all this stuff and some experienced advice would go a long way. 很抱歉成为新手,但是我自学了所有这些东西,并且一些经验丰富的建议会走很长一段路。

thanks 谢谢

That sounds correct. 听起来很正确。

The slowest part of your task is downloading the pages over the network. 您的任务中最慢的部分是通过网络下载页面。

Your program starts downloading a bunch of pages at once, waits for them to arrive, then parses them all almost instantly. 您的程序立即开始下载一堆页面,等待它们到达,然后几乎立即解析它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM