Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
JDP0512
3 discussion posts
Is it possible to write a script with DF to pull a DIV value from a URL using any of the BFS functions?
Feb 2, 2023  • #1
User Image
JLJTGR
100 discussion posts
I'm sure you could using a C# script as that has all of .NET behind it. Any particular reason to want it done with the BFS namespace? Unfortunately .NET is great at parsing XML but not HTML so much. Depending on how complex the webpage is will determine how elegant the C# script would be.
Feb 4, 2023  • #2
User Image
JDP0512
3 discussion posts
What I'm trying to accomplish is copying three specific value from a webpages HTML and inserting them into a certain open excel file. I'm not an expert with C# you think you could help me out? If you could just get me started with the C# I should be able to figure the rest out.
• Attachment [protected]: Value 1.PNG [3,527 bytes]
• Attachment [protected]: value 2.PNG [4,312 bytes]
• Attachment [protected]: value 3.PNG [2,331 bytes]
Feb 5, 2023 (modified Feb 5, 2023)  • #3
User Image
JLJTGR
100 discussion posts
Only BFS staff can read protected attachments such as those images.

I would say that the Excel sheet part is actually the hardest. But, I guess I'll show you the easy part...

In the attached script, you can add your corrected URL to the 2nd line and 5th line is an XPath expression to your DIV. If you right-click an element on the webpage and click Inspect or similar, it will open the browser's devtools and highlight your DIV in the source. Right-click that and copy the XPath expression and use that in the 5th line.

As I said in my last post, .NET is terrible at reading HTML, but DF allows you to add references to other libraries. I added System.Xml.XPath from the .NET Framework and HtmlAgilityPack... the latter you have to download separately then browse to it when adding the reference. I had wanted to make a solution without outside libraries, but this makes it so much easier. The distributers make it bafflingly hard to download the library outside of NuGet.org... so you have to get the .nupkg file and extract it as though it were a ZIP. I used the netstandard1.3 file.

As for the Excel part, I honestly don't know what you should do there. I'm not sure I would have recommended DF for doing that part... but I'm not sure what I would use in any case.
2023-02-05 09_55_33-Scripted Function _ DisplayFusion Pro on Steam 10.0 (Beta 19).png
2023-02-05 09_55_33-Scripted Function _ DisplayFusion Pro on Steam 10.0 (Beta 19).png
Feb 5, 2023  • #4
User Image
JDP0512
3 discussion posts
Thanks! With a little editing I was able to retrieve the full HTML with the above but not the Div Value. Due to UAC on this machine I wont be able to use any references outside the .NET 4 framework though. Back to square one....
Feb 5, 2023  • #5
Keith Lammers (BFS)'s profile on WallpaperFusion.com
@JLJTGR: Thanks for trying to help out!

@JDP0512: As JLJTGR mentioned, HTML parsing is actually really difficult to do, and then exporting to Excel is a whole other can of worms. While it is possible to run whatever C# code you like in a DF Scripted Function, that kind of script is well outside the scope of what we'd provide as an example, sorry!
Feb 7, 2023  • #6
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(1)  Login to Vote(-)