亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
Selenium&EmguCV實現(xiàn)爬蟲圖片識別
作者:網(wǎng)絡轉載 發(fā)布時間:[ 2015/4/28 11:13:00 ] 推薦標簽:Selenium 圖片識別 爬蟲

  Selenium內置了截圖方法,只能截取瀏覽器中顯示的內容,找到一個全屏截圖的方式(內置截圖+控制滾動條,圖片拼接)
```C#
public static Bitmap GetEntereScreenshot(IWebDriver _driver)
{
Bitmap stitchedImage = null;
try
{
long totalwidth1 = (long)((IJavaScriptExecutor)_driver).ExecuteScript("return document.body.offsetWidth");//documentElement.scrollWidth");
long totalHeight1 = (long)((IJavaScriptExecutor)_driver).ExecuteScript("return  document.body.parentNode.scrollHeight");
int totalWidth = (int)totalwidth1;
int totalHeight = (int)totalHeight1;
// Get the Size of the Viewport
long viewportWidth1 = (long)((IJavaScriptExecutor)_driver).ExecuteScript("return document.body.clientWidth");//documentElement.scrollWidth");
long viewportHeight1 = (long)((IJavaScriptExecutor)_driver).ExecuteScript("return window.innerHeight");//documentElement.scrollWidth");
int viewportWidth = (int)viewportWidth1;
int viewportHeight = (int)viewportHeight1;
// Split the Screen in multiple Rectangles
List<Rectangle> rectangles = new List<Rectangle>();
// Loop until the Total Height is reached
for (int i = 0; i < totalHeight; i += viewportHeight)
{
int newHeight = viewportHeight;
// Fix if the Height of the Element is too big
if (i + viewportHeight > totalHeight)
{
newHeight = totalHeight - i;
}
// Loop until the Total Width is reached
for (int ii = 0; ii < totalWidth; ii += viewportWidth)
{
int newWidth = viewportWidth;
// Fix if the Width of the Element is too big
if (ii + viewportWidth > totalWidth)
{
newWidth = totalWidth - ii;
}
// Create and add the Rectangle
Rectangle currRect = new Rectangle(ii, i, newWidth, newHeight);
rectangles.Add(currRect);
}
}
// Build the Image
stitchedImage = new Bitmap(totalWidth, totalHeight);
// Get all Screenshots and stitch them together
Rectangle previous = Rectangle.Empty;
foreach (var rectangle in rectangles)
{
// Calculate the Scrolling (if needed)
if (previous != Rectangle.Empty)
{
int xDiff = rectangle.Right - previous.Right;
int yDiff = rectangle.Bottom - previous.Bottom;
// Scroll
//selenium.RunScript(String.Format("window.scrollBy({0}, {1})", xDiff, yDiff));
((IJavaScriptExecutor)_driver).ExecuteScript(String.Format("window.scrollBy({0}, {1})", xDiff, yDiff));
System.Threading.Thread.Sleep(200);
}
// Take Screenshot
var screenshot = ((ITakesScreenshot)_driver).GetScreenshot();
// Build an Image out of the Screenshot
Image screenshotImage;
using (MemoryStream memStream = new MemoryStream(screenshot.AsByteArray))
{
screenshotImage = Image.FromStream(memStream);
}
// Calculate the Source Rectangle
Rectangle sourceRectangle = new Rectangle(viewportWidth - rectangle.Width, viewportHeight - rectangle.Height, rectangle.Width, rectangle.Height);
// Copy the Image
using (Graphics g = Graphics.FromImage(stitchedImage))
{
g.DrawImage(screenshotImage, rectangle, sourceRectangle, GraphicsUnit.Pixel);
}
// Set the Previous Rectangle
previous = rectangle;
}
}
catch (Exception ex)
{
// handle
}
return stitchedImage;
}
```
  后的是根據(jù)傳入的元素和全屏截圖,獲取到價格元素的圖片
```C#
public static Image SnapshotV2(this IWebElement element, Bitmap bitmap)
{
Size size = new Size(
Math.Min(element.Size.Width, bitmap.Width),
Math.Min(element.Size.Height, bitmap.Height));
Rectangle crop = new Rectangle(element.Location, size);
return bitmap.Clone(crop, bitmap.PixelFormat);
}
```
  運行效果如下:


  

上一頁12下一頁
軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 制服丝袜手机在线 | 国产视频黄色 | 成年性生交大片免费看 | 中文字幕日韩欧美 | 国内黄色片 | 日韩视频在线观看一区二区 | 九九99九九在线精品视频 | 日韩亚州 | 天堂亚洲欧美日韩一区二区 | 在线亚洲精品视频 | 瑟瑟网站免费网站入口 | 婷婷 综合网站 | 97色在线观看免费视频 | 99久久精品国产亚洲 | 日本黄色xxxxx | 亚洲欧美人成人综合在线50p | 一区二区三区免费精品视频 | 国产成人一区二区 | 欧美不卡在线 | 看真人视频a级毛片 | 欧美国产成人一区二区三区 | 亚洲日本中文字幕 | 成人国产精品视频频 | 日韩免费高清一级毛片在线 | 一级特黄aaa大片在 一级特黄aaa大片在线观看 | 福利片在线观看免费高清视频 | 黄色免费在线网址 | 成人在线天堂 | 成人在线观看国产 | 理论片日韩 | 午夜嘿嘿 | 一级女性黄 色生活片 | 99视频在线观看免费视频 | 首页 动漫 亚洲 欧美 日韩 | 国产成人不卡亚洲精品91 | 高清人人天天夜夜曰狠狠狠狠 | 欧美一级www片免费观看 | 欧美污视频网站 | 欧美激情一区二区三区在线播放 | 亚洲成综合人影院在院播放 | 免费黄色欧美 |