gpt4 book ai didi

c# - WebClient DownloadString 不返回任何内容

转载 作者:太空狗 更新时间:2023-10-29 21:13:09 24 4
gpt4 key购买 nike

我想从海盗湾的搜索查询中获取源代码,我的代码中有这个但它没有返回任何内容:

WebClient webpage = new WebClient();
string source= webpage.DownloadString("http://thepiratebay.sx/search/documentary/0/99/0");

最佳答案

这是一个快速测试:

xaml:

<Label Content="{Binding ElementName=window_name, Path=SourceTest}"></Label>
<Label Content="{Binding ElementName=window_name, Path=SourceTest2}"></Label>

代码:

string source_url = "http://thepiratebay.sx/search/documentary";

WebClient webpage = new WebClient();
SourceTest = webpage.DownloadString(source_url);
if (SourceTest == "")
SourceTest = "stream was empty.";


source_url = "http://www.google.com";

webpage = new WebClient();
SourceTest2 = webpage.DownloadString(source_url);
if (SourceTest2 == "")
SourceTest2 = "stream was empty.";

您的 URL 将返回一个空字符串,而另一方面,Google 会为您提供您正在寻找的来源。

编辑:正如我所假设的,您需要像网络浏览器一样进行识别。这适用于您的查询:

string source_url = "http://thepiratebay.sx/search/documentary/0/99/0";

using (var webpage = new WebClient())
{
webpage.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
SourceTest = webpage.DownloadString(source_url);
}

关于c# - WebClient DownloadString 不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19577586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com