I am scraping a webpage. The webpage consists of 48 entries. After 48 entries it gives a Load more results button. I need to get all the products from this page. How can I do it? For scraping, I am using Python, LXML, and Requests Library.
I will be thankful for your Help.
My Code :
import requests
from lxml import html
home_page = requests.get('https://www.anntaylor.com/')
website_tree = html.fromstring(home_page.content)
categories = website_tree.xpath('//a[@role="menuitem"]')
def my_function(urls):
category_page = requests.get(urls)
category_tree = html.fromstring(category_page.content)
product_data = category_tree.xpath('//div[@class="product-wrap"]') #//div[@class='product-wrap']
for title in product_data:
print(title.xpath('.//@href')[0])
# //link[@rel="next"]
print(len(product_data))
print(urls)
for i in categories:
urls = i.xpath('./@href')
# print(urls[0])
my_function(urls[0])
print(len(categories))