尝试在Powershell中从生成器获取文本

kmpatx3s  于 2023-02-04  发布在  Shell
关注(0)|答案(1)|浏览(118)

我想用一个

Invoke-WebRequest -Uri https://www.lingerandlook.com/Names/StreetNameGenerator.htm |Select-Object yadda yadda

要得到一个3字"甜蜜的街道名称"从这个网站,但我无法让它得到正确的内容或找到文本时,解析网站。有人能帮助我吗?
尝试在powershell中查找页面上的内容,但无法看到生成的文本,只有它的西班牙语是$name。我通常是新的powershell,所以不确定如何前进

vwoqyblh

vwoqyblh1#

在这种特殊情况下,您可以从该站点获取生成的街道名称列表,如下所示:

$request = Invoke-WebRequest -Uri 'https://www.lingerandlook.com/Names/StreetNameGenerator.htm'
$table   = @($request.ParsedHtml.getElementsByClassName('tlist'))[0]

$table.deleteRow(0) # remove the top table row 'If you want to invent your own name...'

# next move through all the data rows and join the content of its cells to form a street name
$streetList = foreach ($row in $table.Rows) {
    ($row.Cells | ForEach-Object { $_.innerText }) -join ' '
}

# output the resulting array to console
$streetList

# or save it to some file
$streetList | Set-Content -Path 'X:\Somewhere\StreetList.txt'

结果

Amber Acorn Acres
Auburn Anchor Alcove
Bent Apple Arbor
Big Autumn Avenue
Birch Axe Bank
Blue Barn Bayou
Bright Beacon Bend
Broad Bear Bluff
Burning Beaver Byway
Calm Berry Canyon
Cinder Bird Chase
Clear Blossom Circle
Cold Bluff Corner
Colonial Branch Court
Cool Bridge Cove
Cotton Brook Crest
Cozy Butterfly Cut
Crimson Butternut Dale
Crystal Castle Dell
Dewy Chestnut Drive
Dusty Cider Edge
Easy Cloud Estates
Emerald Cottage Falls
Fallen Creek Farms
Foggy Crow Field
Gentle Dale Flats
Golden Deer Gardens
Grand Diamond Gate
Green Dove Glade
Happy Elk Glen
Harvest Elm Grove
Hazy Embers Haven
Heather Fawn Heights
Hidden Feather Highlands
High Flower Hollow
Honey Forest Isle
Hush Fox Jetty
Indian Gate Journey
Iron Goat Knoll
Ivory Goose Lace
Jagged Grove Lagoon
Lazy Harbor Landing
Little Hickory Lane
Lone Hills Ledge
Lonely Holly Manor
Long Horse Meadow
Lost Island Mews
Merry Lake Niche
Middle Lamb Nook
Misty Leaf Orchard
Noble Log Pace
Old Maple Park
Orange Mill Pass
Pearl Mountain Path
Pied Nectar Pike
Pleasant Nest Place
Pretty Nut Point
Quaint Oak Promenade
Quaking Panda Quay
Quiet Peach Race
Red Pebble Ramble
Rocky Pine Ridge
Rose Pioneer Road
Rough Pond Round
Round Pony Rove
Rustic Prairie Run
Sandy Pumpkin Saunter
Shady Quail Shoal
Silent Rabbit Stead
Silver Rise Street
Sleepy River Stroll
Small Robin Summit
Square Rock Swale
Still Shadow Terrace
Stony Sky Trace
Strong Snake Trail
Sunny Spring Trek
Sweet Squirrel Turn
Tawny Stone Twist
Tender Swan Vale
Thunder Timber Valley
Turning Treasure View
Twin Turtle Villa
Umber View Vista
Velvet Wagon Wander
White Willow Way
Windy Zephyr Woods

相关问题