CA
afraid-scarlet
Web Scraper when exported to csv is adding all records in the same row
I am using actor (Web Scraper). Scraping data from an hotels aggregator website where I want all hotel name,address, etc in different rows. Right Now all the records and merged into one row. Ex- All hotel name in one cell. Similarly all address in one cell. Kindly help! Do I need to add something in the code or change some setting?
10 Replies
I guess this is because your selector is appearing multiple times on the page so if you write
$('some selector').text()
it will get text from all elements. So you are pushing it all to one row in the dataset.afraid-scarletOP•3y ago
@HonzaS I want all the texts and the element name is same. My only problem is with the structure of data. I've tried adding \n and also insertRow() function. \n throws error and insertRow() function doesn't really change anything for me. Is there a way to separate this data into multiple rows just how a dataset looks like?
yes, you need to iterate through all the elements, best would be to use map function
afraid-scarletOP•3y ago
Hi @HonzaS , Can you add a code here. I am not used to writing code. Have tried few things but throws error. Please help if you can.
I can if you share the url
afraid-scarletOP•3y ago
https://nidhi.tourism.gov.in/directory?categoryCode=01&subcategory=HT
I need Hotel Name, Address, Email, Phone, URL
@hexian just advanced to level 2! Thanks for your contributions! 🎉
return $('.listing-block').map(function () { return {HotelName:$(this).find('div.hotel-details h2').text(),Address:$(this).find('div.hotel-details p').text()};}).get();
@HonzaS just advanced to level 13! Thanks for your contributions! 🎉
afraid-scarletOP•3y ago
Hey! It worked. Thanks @HonzaS
Can you also help me with the pagination of this page?
Where do I add next link and how do I write it?