简体   繁体   English

如何让C#打开网站并在其上运行JavaScript

[英]How to have C# open a website and run javascript on it

I am trying to make a program that automatically buys items for me I have gotten everything to work, but I am trying to make it so when you click a button it runs java script on a website ex. 我正在尝试制作一个可以自动为我购买商品的程序,我已经可以使用所有工具,但是我正在尝试这样做,因此,当您单击按钮时,它将在网站ex上运行Java脚本。 google.com (basically making it automatic instead of having to do f12 go to console then hit enter). google.com(基本上使其自动完成,而不必执行f12进入控制台,然后按Enter键)。

I have been able to get it to work when I do F12 我做F12的时候就可以正常工作了

Not too much to show im stumped on where to start. 没有太多的东西可以显示我对如何开始感到困惑。

I want to make it so (in my C# program) it automatically runs java script on a website when you click a button. 我想这样做(在我的C#程序中),当您单击按钮时,它会自动在网站上运行Java脚本。

I see several ways: 我看到几种方法:

  1. Chrome extension that allows to make what you asked for. Chrome扩展程序可以实现您的要求。 Sure it works only if you browser is open. 当然,只有在您打开浏览器后,它才起作用。
  2. The other way is to explore whether the target site accept ajax requests and allows to perform buying operations. 另一种方法是探索目标站点是否接受ajax请求并允许执行购买操作。 Something like a simple api. 类似于简单的api。 So you can call this from your C# program. 因此,您可以从C#程序中调用它。

To test if they has API you can look at a network requests in chrome dev tools and find ajax requests for needed operations, something like /buy?product_id=231 or products?page=3 . 要测试他们是否具有API,您可以在chrome开发工具中查看网络请求,并找到所需操作的ajax请求,例如/buy?product_id=231products?page=3 Then try to fetch that urls and get a correct response. 然后尝试获取该网址并获得正确的响应。 It means you can send such requests from your C# program. 这意味着您可以从C#程序发送此类请求。

There could be some pitfalls like required cookies or headers, but it is just a matter of time to find this out. 可能会遇到一些陷阱,例如所需的cookie或标题,但是发现它只是时间问题。

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

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