简体   繁体   English

如何制作WatiN内部http请求?

[英]how to make a WatiN internal http request?

just wonder whether it's possible to make an internal extra request to an image without using separate code. 只是想知道是否可以在不使用单独代码的情况下对图像进行内部额外请求。 eg, 例如,

var browser = new IE();
string url = "https://www.google.com/"
browser.GoTo(url);

// extract http://www.google.com/images/logos/ps_logo2.png 
//using a http request using browser ?

browser.Images wont let me save the image :|, how can I make an external request to get the image ? browser.Images不会让我保存图像:|,如何获取外部请求来获取图像?

如果您已经知道映像的URL,则可以使用System.Net命名空间中的WebClient类。

byte[] image = new WebClient().DownloadData("https://www.google.com/images/logos/ps_logo2.png");

Maybe these steps work: 也许这些步骤有效:

  • Find the image on the page: 在页面上找到图像:
var image = browser.Image(Find.First())
  • Get the href and navigate to it 获取href并导航到它
browser.GoTo(image.href);
  • Get a screenshot of the page: 获取页面截图:
var screenshot= new UtilityClasses.CaptureWebPage(_browser).CaptureWebPageImage(false, false, 100);
  • And then trim the screenshot to the size of the image. 然后将屏幕截图修剪为图像的大小。 To get the Height and Width of the image you need the call 要获得图像的高度和宽度,您需要进行调用
var width = image.Style.GetAttributeValue("width");
var height= image.Style.GetAttributeValue("height");
  • Now you can create a new Image with the correct height and width. 现在,您可以使用正确的高度和宽度创建新图像。

HTH, Jeroen HTH,Jeroen

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

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