Python Forum
Newbie help with lxml scrapping - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Newbie help with lxml scrapping (/thread-31883.html)



Newbie help with lxml scrapping - chelsealoa - Jan-08-2021

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 https://omegle-online.com


RE: Newbie help with lxml scrapping - Larz60+ - Jan-08-2021

what is A$ set to?

I suspect you're not getting past the request.get statement.
You should check page.status_code == 200
if see if all went well, and display error if not.