简体   繁体   English

如何在我的程序中从网站上获取图片?

[英]How can I get a picture from the site in my program?

Good afternoon. 下午好。 There is a site that hosts announcements here I need to get a phone number on the page any announcement, for example here The phone number is represented as a picture. 有一个网站在这里托管公告我需要在页面上获得任何公告的电话号码,例如这里电话号码表示为图片。 I wanted to get the link to the picture and save this picture and recognize this picture. 我想获得图片的链接并保存这张图片并识别出这张照片。 But when I started to get a link to the picture in my program, I saw that this picture generated java script. 但是当我开始在程序中获得图片的链接时,我看到这张图片生成了java脚本。 Here is the code in which I'm trying to get a link to a picture in my program: 这是我试图在程序中获取图片链接的代码:

.....
HtmlNode bodyNode7 = doc.DocumentNode.SelectSingleNode(@".//*//table[6][@class='objectView']//tr[2]//td");
Console.WriteLine(bodyNode7.InnerText.ToString());
.....

I use HtmlAgilityPack library (C#) for parsing the picture link. 我使用HtmlAgilityPack库(C#)来解析图片链接。 I opened the source code of this page ( here ) and saw Javascript that generates picture: 我打开了这个页面的源代码( 这里 ),看到生成图片的Javascript:

<tr id="ctl00_cphBody_FlatSell_Obj_adapterObject_trPhones" style="background-color: white">
        <th>Телефоны:</th>
        <td>
                    <script language="javascript" type="text/javascript">document.write(decs("0x88e36b6d468b03acca9737a99ba0fffe05cb3a53de8858b798194826c94719e2193434b3377d69745a1a28879291ecfd69c703de931ac8f551fe22229ef49160"));</script>
        </td>
</tr>

In the javascript is used function decs() to generate the picture. 在javascript中使用函数decs()来生成图片。 Here is the code: 这是代码:

function decs(a){
return deco(key,hexToString(a),0,1,iv)
};

If I understand correctly, this function created a link to an picture with the phone number or this function created this picture. 如果我理解正确,此功能创建了一个带有电话号码的图片的链接,或者此功能创建了这张图片。 In this case, the function uses a parameter "key". 在这种情况下,该函数使用参数“key”。 How to create this parameter, I do not know. 如何创建这个参数,我不知道。

Question: How can I get the link to this picture with a phone number or download this picture with a phone number in my program? 问题:如何通过电话号码获取此图片的链接,或者在我的程序中使用电话号码下载此图片?

You have several options. 你有几个选择。 One is to use a library like OpenWebkitSharp that hosts an instance of Webkit within your .NET application, you can use this to execute any scripts on the page and then inspect the resultant DOM to extract the images. 一种是使用像OpenWebkitSharp这样的库来托管.NET应用程序中的Webkit实例,您可以使用它来执行页面上的任何脚本,然后检查生成的DOM以提取图像。 The library is located here: http://code.google.com/p/open-webkit-sharp/ 该图书馆位于: http//code.google.com/p/open-webkit-sharp/

However hosting webkit within your application means it's going to take a while to load and will consume large amounts of memory. 但是,在您的应用程序中托管webkit意味着它需要一段时间才能加载并消耗大量内存。 You'll need to keep it frequently patched an updates to webkit come out on an almost weekly basis. 你需要经常修补它几乎每周都会发布webkit的更新。

Another option, assuming the page's HTML and Javascript stays constant, is to extract features using Regular Expressions and then doing the conversion yourself. 假设页面的HTML和Javascript保持不变,另一个选择是使用正则表达式提取功能,然后自己进行转换。

You would have a regex that finds the " decs( " text and extracts the hex-encoded text afterwards and then you'd feed it into your own implementation of the decs function, which should be easy to do. 你会有一个正则表达式找到“ decs( ”文本并在之后提取十六进制编码的文本,然后你将它提供给你自己的decs函数的实现,这应该很容易做到。

HTH. HTH。

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

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