简体   繁体   中英

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. 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. I opened the source code of this page ( here ) and saw Javascript that generates picture:

<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. 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". 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. The library is located here: 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. You'll need to keep it frequently patched an updates to webkit come out on an almost weekly basis.

Another option, assuming the page's HTML and Javascript stays constant, is to extract features using Regular Expressions and then doing the conversion yourself.

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.

HTH.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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