Jump to content

Pull First And Last name


Recommended Posts

Okay I alwys have trouble doing things like this.

I am trying to pull the first name under the variable $FirstName

And the second name under the variable $Lastname

This url always just loads a new name so I always have random names

http://www.behindthename.com/random/random.php?number=2&gender=m&surname=&all=yes

But I cant seem to accuratly pull them pleaes help thank you

Link to comment
Share on other sites

I was looking to copy somthing like this

$vLoremText = _StringBetween(_INetGetSource('http://lipsum.com/feed/html'), '<div id="lipsum">', '</div>')

MsgBox(0, "", StringReplace(StringReplace($vLoremText[0], '</p>', ''), '<p>', ''))

but I dont really understand how to

Link to comment
Share on other sites

From the website you listed, this works for me:

#include <string.au3>
#include <INet.au3>

$Source = _INetGetSource('http://www.behindthename.com/random/random.php?number=2&gender=m&surname=&all=yes')
$Name = _StringBetween($Source, '<a href="/name/', '</a> </font></center><br><br><br>')
If @error Then Exit
$FullName = _StringProper(StringRegExpReplace($Name[0], '" class="plain">.*</a>  <a href="/name/.*" class="plain">', ' '))
Msgbox(32, 'Extracted Name', $FullName)
Link to comment
Share on other sites

OMG it works thank you so much I was trying so many diffrent things im going analyze how you did it and see If I cant figure it out for my self and future reference.

Although If you could help me how can I now divide the variable $FullName into two variable

I image the best way to do this is by saying anything in front of the first space = $Firstname

Anything after space is $Lastname How do I do this I can only find things to divide a string by its length not spaces.

Link to comment
Share on other sites

You can use StringSplit or _StringBetween or even StringRegExpReplace...here is an example with _StringBetween

#include <string.au3>
#include <INet.au3>

$Source = _INetGetSource('http://www.behindthename.com/random/random.php?number=2&gender=m&surname=&all=yes')
$Name = _StringBetween($Source, '<a href="/name/', '</a> </font></center><br><br><br>')
If @error Then Exit
$FullName = _StringProper(StringRegExpReplace($Name[0], '" class="plain">.*</a>  <a href="/name/.*" class="plain">', ' '))
$Firstname = _StringBetween($FullName, '', ' ')
$Lastname = _StringBetween($FullName, ' ', '')
Msgbox(32, 'Extracted Name', 'Full Name = ' & $FullName & @LF & 'First Name = ' & $Firstname[0] & @LF & 'Last Name = ' & $Lastname[0])

Let me know if you need me to add comments to explain what is going on in the script

Edited by Varian
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...