Как спарсить название и цену с сайта?

Есть сайт steamfarmkey.ru
Надо получить название игр и цены к ним. С помощью каких библиотек посоветуете сделать?
Если не затруднит, сделайте пример. Буду благодарен.
  • Вопрос задан
  • 293 просмотра
Решения вопроса 1
a13xsus
@a13xsus
Lazy developer
Легче всего на Питоне, используя lxml и requests. Если их нет, то:
sudo apt-get install python-lxml
sudo apt-get install python-requests

Сам скрипт:
#!/usr/bin/python
from lxml import html
from lxml import etree
import requests
import sys

url = sys.argv[1]
page = requests.get(url)
tree = html.fromstring(page.content)

games = tree.xpath('//tbody/tr[contains(@class, "good")]')

for game in games:
	game_name = game.xpath('./td[@class="good-title"]/div/span/text()')[0]
	prices = game.xpath('./td[@class="good-price text-center"]/div/span[@class="rub"]/span[@class="price-value"]')
	for price in prices:
		price_value = price.xpath('./text()')[0]
		print('{}, {}').format(game_name.encode('utf-8'), price_value.encode('utf-8'))


Запускаем:
sudo python /home/automatik/scrape.py http://steamfarmkey.ru

Получаем (цены в рублях):
spoiler
Uncrowded, 2.00
WALLSLIDE, 11.00
Winter Novel, 5.00
SWEATER? OK!, 9.00
Conclusion, 1.80
The District, 1.99
QUBIC, 1.50
Sandstorm, 1.40
Eight Mini Racers, 1.65
Linked, 1.70
Akin, 1.70
Attempt[42], 1.74
Puzzle Cube, 1.70
Square n Fair, 1.70
Felix Jumpman, 1.70
Forgotten Heroes, 1.50
hack_me, 1.50
The Return Home, 1.00
Nash Racing, 1.50
Yet Another World, 1.40
HardCube, 1.40
Cowboy zombie, 1.30
Yeti Adventure, 1.35
PuppyStory, 1.35
The Next Door, 1.95
Princess.Loot.Pixel.Again, 1.30
Dungetris, 1.30
Bye-Bye, Wacky Planet, 1.70
Beast Blaster + Cyborg Detonator + Zombie Boom, 1.50
Absconding Zatwor + Break Into Zatwor + Fiends of Imprisonment, 1.50
GooCubelets + GooCubelets 2 + GooCubelets: The Algoorithm, 1.50
Why So Evil +   Why So Evil 2: Dystopia + Brilliant Bob + They Came From The Moon, 1.00
Hello From Indiana, 0.50
Its your last chance in new school, 0.50
Luci:Horror Story, 1.45
Little ALLIGATOR, 1.50
KEK Story, 1.80
Landfill [Карточки можно продать!], 2.00
Cube Master, 0.50
Sixtieth Kilometer, 1.75
Red Lake, 1.75
Rise of the Ancients, 1.75
Hover Hazard, 1.30
Burst, 1.30
Wishmaster, 1.20
Trolley Gold, 1.10
Go Mission:® Space Travel, 1.45
Bibou®, 1.45
Kabitis®, 1.45
JumpBall®, 1.40
Drop Hunt - Adventure Puzzle, 1.15
The Last Hope, 1.40
The Last Hope: Trump vs Mafia, 1.15
The Lost Valley, 1.70
Gridberd, 1.70
Lex Mortis, 1.70
Find Out, 1.70
Tales of Destruction, 1.05
Finnish Roller, 1.05
The Magical Silence, 1.80
The Big Elk, 1.80
The Last Error, 1.80
Western FPS, 1.40
Invention, 1.40
Way of Hero, 1.45
Bold New World, 0.40
Turn Around, 0.70
$1 Ride, 1.75
Ampersand, 1.74
Calcu-Late, 1.75
Catch a Falling Star, 1.75
Clergy Splode, 1.74
Cosmic Dust & Rust, 1.75
Deep Space Dash, 1.75
Drayt Empire, 1.75
Eaten Alive, 1.74
Escape Machines, 1.75
Final Quest, 1.75
Final Quest II, 1.74
Flesh Eaters, 1.74
Freebie, 1.50
Germ Wars, 1.74
Hyper color ball, 1.75
Kivi, Toilet and Shotgun, 1.74
Laraan, 1.75
Lup, 1.74
Midnight Carnival, 1.74
Monster Puzzle, 1.75
Neon Hardcorps, 1.75
New kind of adventure, 1.74
OR, 1.75
Project Druid - 2D Labyrinth Explorer- [Карточек НЕТ!], 1.75
Shape Shifter, 1.75
Star Chronicles: Delta Quadrant, 1.74
Star Drifter, 1.75
Star Fields, 1.75
Stellar 2D, 1.74
Stone Age Wars, 1.75
Super Mega Neo Pug, 1.75
Super Mustache, 1.75
Super Space Pug, 1.75
BitRay, 1.09
Terra Incognita ~ Chapter One: The Descendant, 1.74
The Land of Dasthir, 1.75
The Tower Of Elements, 1.74
Tinboy, 1.74
Town of Night, 1.74
Turbo Pug, 1.74
Turbo Pug 3D, 1.74
Turbo Pug DX, 1.75
Warriors of Vilvatikta, 1.75
Daily Chthonicle: Editor's Edition, 1.99
SkyTime, 1.99
Citalis, 1.99
Crab Dub, 1.35
Bacteria, 1.10
Black Sand Drift, 1.10
BitMaster, 1.50
Cyber City 2157: The Visual Novel, 1.15
Dear RED - Extended, 1.10
Energy Balance, 1.10
Energy Cycle, 1.10
Farnham Fables, 1.15
Gone In November, 1.20
Hexoscope, 1.10
Hiiro, 1.25
Hyposphere, 1.15
It's Spring Again, 1.00
Just Hero, 1.15
Liveza: Death of the Earth, 1.20
Machine Made: Rebirth, 1.15
Madrobot X, 1.50
Make it indie!, 1.00
Merger 3D, 1.15
NeverEnd, 1.35
NORTH, 1.25
Puzzle Galaxies, 1.25
Retention, 1.00
Russian SuperHero Dead Ivan, 1.25
SweatShop, 1.15
Vindictive Drive, 1.50
Absoloot, 1.99
Bloodbath Kavkaz, 1.70
Stigmat, 1.00
Anykey Simulator, 1.88
Sig.NULL, 1.85
28 Waves Later, 1.49
Spakoyno: Back to the USSR 2.0, 1.40
Lost In Woods 2, 1.85
Experience, 1.45
Invasion, 1.20
WOLF SIMULATOR [На данный момент карт нет!], 2.10
Abandoned Knight, 1.45
Darconika: The Cube of Soul, 1.66
Squeezone, 1.49
Space Incident, 1.89
Minimized, 1.89
The Pit And The Pendulum, 1.68
Inverted, 1.98
Physic Monster, 1.98
Totem, 1.68
Alien Run, 1.28
Night Forest, 1.36
PixBit, 1.66
Under Zero, 1.18
Platro, 1.98
Russian Horror Story, 1.25
Detective Noir, 2.10
Casino Noir, 2.10
Golden Swords, 1.95
Reptilians Must Die!, 1.99
Hell`s Little Story, 2.10
Triangle, 1.99
Other Tanks, 1.70
Time Of Silence, 2.10
Sleight, 2.10
Galactic Fighter, 2.10
Ultimate Russian Zombie Rush, 1.99
Altar Guardian, 1.99
Mars Industries, 1.68
Midsummer Night, 1.70
Iron Impact, 1.99
Tank Blast, 2.10
The Atomy, 1.50
Cubium Dreams, 1.99
NUKED KNIGHT, 1.45
Armored Gear, 2.10
Castle Werewolf 3D, 1.99
Jump Like A Pirate, 2.10
Chicka Wars | Chicken Meat, 0.92
CosmoLands | Space-Adventure, 0.97
DinoOps, 0.95
Etaria | Survival Adventure, 0.93
GrottyScape, 0.95
MontaSayer, 0.90
Reed, 0.95
Socxel | Pixel Soccer, 0.90
StoneBack | Prehistory, 0.93
Garden Rescue, 2.00
Garden Rescue: Christmas Edition, 2.00
Odysseus: Long Way Home, 2.00
Rush for gold: Alaska, 1.14
Rush for gold: California, 1.14
The chronicles of Emerland. Solitaire., 1.10
Tropical Fish Shop 2, 1.14
Call to 10, 1.80
Case #8, 1.80
Jackal, 1.80
Krampus, 1.80
Whispers, 1.80
GRUZCHIK, 1.00
Only One Hope, 0.50
Yellow: The Yellow Artifact, 0.30
Moon Colonization Project, 0.25
STARUSHKO LUB, 0.25
Heavenly Battle, 1.80
Trump Simulator 2017, 0.90
Hoplite, 1.40
KORABLIK, 0.95
Cat Goes Platform, 0.97
Ball of Light, 0.95
Overhell, 0.97
Project Pulsation, 1.76
Infinitum, 1.28
Z.I.O.N., 1.37
Invisible Mind, 1.77
Fergus The Fly, 0.80
Jumping Tank, 0.80
Adventures of Hooi, 1.05
Offroad: VR, 1.34
Flight Simulator: VR, 3.96
Staircase of Darkness: VR, 1.50
Ropes And Dragons VR, 1.75
Crazy Fun - FootRock, 1.77
Killbot, 1.77
Rescue your chickens, 2.50
Santa's Big Adventures, 2.50
Conan the mighty pig, 2.50
Fruit Arranger, 2.50
Little Jack's Adventures, 2.50
Riot of the numbers, 2.50
Pro Skater 2D, 2.50
The Orb Chambers™, 1.99
The Orb Chambers II, 1.99
CountDown, 2.00
Fairyland: Fairy Power, 1.30
Fairyland: Incursion, 1.49
Snowman, 1.15
Moccasin, 1.65
Nanoborg, 1.80
Mouse in Lab, 1.20
KickHim, 0.99
Brain In My Head, 0.99
HellAngel, 0.99
Steel Invaders, 0.98
ZombieCarz, 0.98
Mad Hunter, 0.90
Uncompromising Trash, 1.15
Mortifero Motus, 1.35
Magazime Editor, 1.70
Ballistic Protection, 0.99
BitRay2, 1.09
Nightmare, 1.99
Epsilon corp., 1.99
REVENGE: First Blood, 1.10
Fight or Die, 1.25
Slash or Die, 1.20
Fluffy, 0.99
Head Shot, 0.75
Slingshot people, 0.70
Unexpected Day, 0.60
Numberline, 0.95
Lone Leader, 1.15
CRACKHEAD, 0.38
PIGMENTUM, 0.60
Star Project, 1.99
Itineris, 1.10
Keyboard Killer, 1.10
Escape This, 1.80
Score a goal (Physical football), 1.60
Existentia, 1.05
Last Answer, 1.10
On The Path, 1.49
Bootombaa, 2.95
The Lords of the Earth Flame, 1.19
Bunny & Piggy, 1.40
Grind Zones, 0.80
Grand Pigeon's Duty, 1.80
Greenwood the Last Ritual, 1.50
Trashville, 0.40
FBI MANIA, 1.70
Word Killer: Zorgilonian Chronicles, 1.25
Lost Base Escape, 0.47
The Sunset, 1.23
Remain, 1.49
Bequest, 2.00
Eightieth Kilometer, 2.00
Turn Around DLC - Additional Campaign #1 - Horror City, 1.50
Turn Around DLC - Additional Campaign #2 - Slaughterhouse, 1.50
Turn Around DLC - Additional Campaign #3 - The village of grandfather, 1.50
Turn Around DLC - Additional Campaign #4 - House of forester, 1.50
Bacteria Collector's Edition Content, 3.50
Bacteria Soundtrack, 3.50
Black Sand Drift Collector's Edition Content, 3.50
Crab Dub Soundtrack, 3.50
Energy Balance Soundtrack, 3.50
Energy Cycle Collector's Edition Content, 3.50
Energy Cycle Soundtrack, 3.50
Farnham Fables Tape 1 Episode 2, 3.50
Gone In November Collector's Edition Content, 3.50
Hexoscope Collector's Edition Content, 3.50
Hexoscope OST, 3.50
Hiiro - Collector's Edition Content, 3.50
It's Spring Again Collector's Edition Content, 3.50
Just Hero Soundtrack, 3.50
STEAM Аккаунт для фарма, 19.00
Rogue Port - Blue Nightmare, 10.00
Wrath of Anna, 3.50
Survival Driver, 1.60
hack_me 2, 1.50
Project: R.E.B.O.O.T, 1.30
Project: R.E.B.O.O.T 2, 1.20
Madness, 1.30
Magic Box, 1.30
Inner silence, 1.70
Flagster, 1.60
Heaven Island - VR MMO, 0.99
A grande bagunça espacial - The big space mess, 0.99


Прочесть об этом можно здесь: python-guide-pt-br.readthedocs.io/en/latest/scenar...
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@heahoh
Full stackoverflow developer
С помощью curl и preg_match. Сделайте сами
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы