I'm new to web scraping and I want to scrape the information of all the products from a website.
I've written a sample code to scrape data which goes as:
def start_requests(self):
urls = [
'https://www.trendyol.com/camasir-deterjani-x-c108713',
'https://www.trendyol.com/yumusaticilar-x-c103814',
'https://www.trendyol.com/camasir-suyu-x-c103812',
'https://www.trendyol.com/camasir-leke-cikaricilar-x-c103810',
'https://www.trendyol.com/camasir-yan-urun-x-c105534',
'https://www.trendyol.com/kirec-onleyici-x-c103806',
'https://www.trendyol.com/makine-kirec-onleyici-ve-temizleyici-x-c144512'
]
for url in urls:
yield scrapy.Request(url=url, callback=self.parse, meta=meta, dont_filter=True)
def parse(self, response):
soup = BeautifulSoup(response.text, 'lxml')
data = re.search(r"__SEARCH_APP_INITIAL_STATE__=(.*?});", response.text)
data = json.loads(data.group(1))
for p in data["products"]:
item=TeknosaItem()
item['rowid'] = hash(str(datetime.datetime.now()) + str(p["id"]))
item['date'] = str(datetime.datetime.now())
item['listing_id'] = p["id"]
item['product_id'] = p["id"]
item['product_name'] = p["name"]
item['price'] = p["price"]["sellingPrice"]
item['url'] = p["url"]
yield item
The code I've written is able to scrape in data for all the products that are listed on first page but as we scroll down the page the page loads more data dynamically via Ajax GET requests and it is not able to scrape that data. I've watched some of the videos and read some articles to but I was not able to figure out how can I scroll data that is being generated dynamically on scrolling. Any help on this will be appreciated.
I found infinite page example on target site: