C# 如何制作网络机器人?(或者其他的东西)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1509010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a web bot? (or something)
提问by PythEch
I need to register to a site programmatically. I did it with VB6 (using the IE Web Browser component), but I don't know how to edit textboxes on a website using WebBrowser. I don't need to do it with Webbrowser, it's just that I know it can be done with it. I just need to insert a username, a password etc. using my program.
我需要以编程方式注册到站点。我是用 VB6 做的(使用 IE Web 浏览器组件),但我不知道如何使用 WebBrowser 在网站上编辑文本框。我不需要用 Webbrowser 来做,只是我知道它可以用它来完成。我只需要使用我的程序插入用户名、密码等。
Thanks
谢谢
采纳答案by Alex Duggleby
Also have a look at the Watin project: http://www.codeproject.com/KB/aspnet/WatiN.aspx
也看看 Watin 项目:http: //www.codeproject.com/KB/aspnet/WatiN.aspx
It's more used for web app testing, but for automating web forms it has great features out of the box.
它更多地用于 Web 应用程序测试,但对于自动化 Web 表单,它具有开箱即用的强大功能。
For a more neutral solution you may also want to check out: http://seleniumhq.org/Again it's a web app testing framework but it's useful for what you want.
对于更中立的解决方案,您可能还想查看:http: //seleniumhq.org/同样,它是一个 Web 应用程序测试框架,但它对您想要的东西很有用。
HTH Alex
亚历克斯
回答by Davorin
You can use HttpWebRequestclass and POST method.
您可以使用HttpWebRequest类和 POST 方法。
回答by Daniel Elliott
Try having a look at WATin. IT will allow you to automate a browser from C#.
尝试看看WATin。IT 将允许您从 C# 自动化浏览器。
It also has a recorder which can be helpful.
它还有一个记录器,可以提供帮助。
You could use HttpWebRequest but if an open-source component (Watin) is not an issue the task will take a lot less time to achieve.
您可以使用 HttpWebRequest 但如果开源组件 (Watin) 不是问题,那么完成任务所需的时间就会少得多。
Kindness,
善良,
Dan
担
回答by PythEch
Thanks to all, I found how to do it with WebBrowser but WatiN looks better.
感谢所有人,我找到了如何使用 WebBrowser 进行操作,但 WatiN 看起来更好。
webBrowser1.Navigate("http://www.somewebsite.com/register.php");
//Wait until website is loaded
do
{
Application.DoEvents();
}
while (webBrowser1.IsBusy == true);
webBrowser1.Document.GetElementById("username"
).SetAttribute("value", textBox1.Text);
//etc.
回答by Frank Bohorquez
Depends if the first span with the class value that you don't want it's always found second u could skip it using a flag
取决于第一个具有您不想要的类值的跨度是否总是在第二个您可以使用标志跳过它
var variable = ie.Span(Find.ByClass("TheClass")).Text;
var x = 0;
if(variable != "" && x == 0){
var variable2=variable
}else{
x++
}
that way you only keep the actual thing u want in "variable2" u could adapt the same code to skip the first one and kept the second. instead of skiping the second one and keep the first. sorry for my bad english :c
这样你只能在“variable2”中保留你想要的实际东西你可以调整相同的代码来跳过第一个并保留第二个。而不是跳过第二个并保留第一个。对不起我的英语不好:c