Python Forum
Noob scraping with lxml check stock
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Noob scraping with lxml check stock
#1
I am interested in using lxml Python 3 and just chose what I thought would be an easy to follow tutorial... I am simply trying to see if a button exists for add to cart to check inventory so I picked a common one "Amazon" and a random item to check.

From that I just wanted to confirm if it was in stock but I have struggled to get anything out of the below code and I am sure it's something obvious but banging my head at this point


page = requests.get('https://www.amazon.com/Sonos-Move-Battery-powered-Bluetooth-built/dp/B07W95RBZM/ref=gbps_img___706175cd?smid=A$
tree  = lxml.html.fromstring(page.content)
instock = tree.xpath('//span[@id="submit.add-to-cart-announce"]/text()')
print('AmazonStock:', instock)
at this point I'd be happy to simply pull some text off a div or span in it

thanks for any pointers

EDIT:
So it occurred to me that maybe this is limited because JS generated HTML has to be interpreted by the browser- for anyone else who may stumble across this, search Amazon, Selenium in the forums.
Reply
#2
Its not essential to use Selenium, you could also use something called splash.

But for a beginner, i would suggest using a library called requests_HTML. It loads JS on a webpage and is easy to use!

Goodluck
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020