Jump to content

How to get the content of a <spam>Content</spam>?


Recommended Posts

Hi, I'm trying to use the IE.au3 to get this content but I'm not sure how to do this.

Is there a way of doing this using XPath or maybe any other smarter way than reading the _IEBodyReadText and cutting the string?

Link to comment
Share on other sites

You are talking about <span>, right ;)

You can access items by ID or name using _IEGetObjById or _IEGetObjByName if there is an ID or name.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Then I would use something like this:

$sHTML = _IEBodyReadHTML($oIE_object)
$asSPAN = StringSplit($sHTML, "<span>", 1)

You get an array with a <Span> in each element. Strip off the "</span>" from the end of each element. That's it.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

well, that the way I didnt want to do... because its an specific span in the middle of HTML.

XPath would do the job... but I dont knwo if there is a way to do this with XPath in IE.au3

Link to comment
Share on other sites

  • Moderators

Kinhow,

You might be able to do it with a RegEx - can you show us an example of the Html and the specific <span> you wish to extract? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Something tells me you're really after the email system, it's ok. You can tell us. We don't bite.

haha no it's not, its really the random generated info that I am after.

Btw mailinator.com is way better than this one

Link to comment
Share on other sites

Get the page source code with Inetread convert it to string using BinaryToString, then find your span id by using StringInStr (given-name in your case) then from that you can use StringTrimLeft or other that would suit your needs.

Edited by xanathos
Link to comment
Share on other sites

Get the page source code with Inetread convert it to string using BinaryToString, then find your span id by using StringInStr (given-name in your case) then from that you can use StringTrimLeft or other that would suit your needs.

I'm not sure if you read the part where I ask if there is some other way than this one.

Link to comment
Share on other sites

You have been offered different solutions for your problem but you don't want to accept them. Why?

It looks like there is no XPath based solution available.

I would stick with the solutions that work.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I was board and decided to do it with my all time favorite UDF, winhttp. SO you'll need to download that before running this.

#include <Array.au3>
#include ".incWinHttp.au3"
$HTML =  _GetSource("http://fakenamegenerator.com/advanced.php")
If @error Then ConsoleWrite("@Error: " & @error & @CR & _
            "@Extended: " & @extended & @CR & _
            "Return: "&$HTML&@CR)
$Stuff = StringRegExp($HTML,"(?i)<spanb[^>]*>(.*?)</span>",3)
_ArrayDisplay($stuff)
$NAme = StringRegExp(StringStripCR($HTML),'<span class="given-name">(.*?)</span> <span class="additional-name">(.*?)</span> <span class="family-name">(.*?)</span>',3)
If Not @error Then MsgBox(0,"Name",$NAme[0]&" "&$NAme[1]&" "&$NAme[2])

Func _GetSource($url, $Hwnd = '', $Agent = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)')
    Local $Error, $CloseHwnd
    Local $aUrl = _WinHttpCrackUrl($url)
    If @error Then Return SetError(1, @error, False)
    If Not $Hwnd Then
        $CloseHwnd = 1
        $Hwnd = _WinHttpOpen($Agent)
        If @error Then Return SetError(2, @error, False)
        _WinHttpSetTimeouts($Hwnd, 0, 10000, 8000, 5000)
    EndIf
    Local $hConnect = _WinHttpConnect($Hwnd, $aUrl[2])
    If @error Then
        $Error = @error
        _WinHttpCloseHandle($hConnect)
        If $CloseHwnd Then _WinHttpCloseHandle($Hwnd)
        Return SetError(3, $Error, False)
    EndIf
    Local $hRequest = _WinHttpSimpleSEndRequest($hConnect, Default, $aUrl[6] & $aUrl[7])
    If @error Then
        $Error = @error
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        If $CloseHwnd Then _WinHttpCloseHandle($Hwnd)
        Return SetError(4, $Error, False)
    EndIf
    If $hRequest Then
        Local $html = _WinHttpSimpleReadData($hRequest)
        If @error Then
            $Error = @error
            _WinHttpCloseHandle($hRequest)
            _WinHttpCloseHandle($hConnect)
            If $CloseHwnd Then _WinHttpCloseHandle($Hwnd)
            Return SetError(5, $Error, False)
        EndIf
    Else
        _WinHttpCloseHandle($hRequest)
        _WinHttpCloseHandle($hConnect)
        If $CloseHwnd Then _WinHttpCloseHandle($Hwnd)
        Return SetError(6, 0, False)
    EndIf
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    If $CloseHwnd Then _WinHttpCloseHandle($Hwnd)
    Return SetError(0, 0, $html)
EndFunc   ;==>_GetSource
Link to comment
Share on other sites

I'm not sure if you read the part where I ask if there is some other way than this one.

lol, I don't really see what kind of solution you want, you need to read the page using whatever method which involves opening a socket, so I don't get your point at all...

Link to comment
Share on other sites

You have been offered different solutions for your problem but you don't want to accept them. Why?

It looks like there is no XPath based solution available.

I would stick with the solutions that work.

The solution of getting the string and cut into various substrings is a possible solution, but I am trying to find another one that could be done with less effort. If I wanted to do manually with text substrings I wouldn't come here to ask you guys for help.

For example ApudAngelorum's solution is a good way using regex, that might help a lot.

lol, I don't really see what kind of solution you want, you need to read the page using whatever method which involves opening a socket, so I don't get your point at all...

I am sorry if I was rude but I just wanted to know if there is a POSSIBLE solution using XPath for example, just like someone did with FF.au3, which is not updated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...