{"id":13973,"date":"2022-10-06T02:47:50","date_gmt":"2022-10-05T21:17:50","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/"},"modified":"2022-10-06T02:47:50","modified_gmt":"2022-10-05T21:17:50","slug":"solved-organizing-data-that-i-am-pulling-and-saving-to-csv","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/","title":{"rendered":"[Solved] organizing data that I am pulling and saving to CSV"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-55291294\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"55291294\" data-parentid=\"55289520\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>You can use pandas to do that. Collect all the data into a dataframe, then just write the dataframe to file.<\/p>\n<pre><code>import pandas as pd\nimport requests\nimport bs4\n\nroot_url=\"https:\/\/www.estatesales.net\"\nurl_list=['https:\/\/www.estatesales.net\/companies\/NJ\/Northern-New-Jersey']\n\nresults = pd.DataFrame()\nfor url in url_list:\n    response = requests.get(url)\n\n    soup = bs4.BeautifulSoup(response.text, 'html.parser')\n    companies = soup.find_all('app-company-city-view-row')\n    for company in companies:\n        try:\n            link = root_url + company.find('a',{'itemprop':\"name url\"})['href']\n            print(link)\n        except:\n            continue\n        response = requests.get(link)\n        soup = bs4.BeautifulSoup(response.text, 'html.parser')\n        company_info = soup.find('div', {'id':'CompanyInfo'})\n        try:\n            name = company_info.find('h1',{'itemprop':\"name\"}).text\n        except:\n            name=\"N\/A\"\n        try:\n            city = company_info.find('span',{'itemprop':\"addressLocality\"}).text\n        except:\n            city = 'N\/A'\n        try:\n            state = company_info.find('span',{'itemprop':\"addressRegion\"}).text\n        except:\n            state=\"N\/A\"\n        try:\n            phone = company_info.find('span',{'itemprop':\"telephone\"}).text\n        except:\n            phone=\"N\/A\"\n\n        temp_df = pd.DataFrame([[name, city, state, phone]], columns = ['Name','City','State','Telephone'])\n        results = results.append(temp_df).reset_index(drop=True)\n\nresults.to_csv('file.csv', index=False)\n<\/code><\/pre>\n<p><strong>Output:<\/strong><\/p>\n<pre><code>print (results)\n                                                  Name       ...             Telephone\n0                               Hub Estate Liquidation       ...        (862) 259-5364\n1                Pink Dog Estate And Moving Sales, LLC       ...        (201) 674-7464\n2         Remember When Antiques And Estate Sales, LLC       ...        (917) 410-7100\n3                                     Always Nostalgia       ...        (201) 388-2598\n4                                  Before &amp; After Corp       ...        (201) 747-5342\n5                               Discovery Estate Sales       ...        (908) 620-1776\n6               Plum Cottage Estate Sales &amp; Appraisals       ...        (732) 788-4101\n7                              Decorate On A Dime, LLC       ...        (908) 380-3340\n8    Remmey Antiques &amp; Fine Art Appraisers &amp; Auctio...       ...        (973) 425-1608\n9                            Easy Picking Estate Sales       ...        (917) 691-6132\n10                               EstateSalesByOlga.com       ...        (908) 337-4240\n11                                          Real McCoy       ...        (973) 418-1286\n12                           Then And Now Estate Sales       ...        (201) 259-8408\n13                                       Insideout,llc       ...        (215) 630-4942\n14           Beacon Hill Estate Sales &amp; Appraisals LLC       ...        (908) 601-5381\n15                            Lori Palmer Estate Sales       ...        (732) 809-3382\n16              Somerset Appraisal And Estate Services       ...        (908) 872-6236\n17           Central Jersey Estate Sales &amp; Liquidators       ...        (908) 625-1622\n18                       C. T. Peters Inc., Appraisers       ...        (732) 747-9450\n19                 Treasures Of Yesterday Estate Sales       ...        (201) 446-2790\n20                Caring Transitions Of Central Jersey       ...        (732) 307-3881\n21                  Attic To The Basement Estate Sales       ...        (732) 778-7674\n22                                Griffin Estate Sales       ...        (908) 447-3044\n23                              Dodge Estate Sales LLC       ...        (973) 714-1401\n24                               Estate Sales By Kathy       ...        (732) 674-7330\n25                                     Curated Estates       ...        (917) 470-9255\n26                              Brownstone Liquidators       ...        (845) 821-3254\n27                                 Jersey Estate Sales       ...        (973) 428-1906\n28                                  Arkay Resale, Inc.       ...        (201) 741-4165\n29                                    Vinylpiggy's LLC       ...        (551) 804-7152\n..                                                 ...       ...                   ...\n116                  Classic Estate Sales &amp; Appraisals       ...        (201) 370-4021\n117                                       Sullivintage       ...        (732) 890-3485\n118                                    A Trotters Sale       ...        (973) 819-8685\n119                                 Shore Estate Sales       ...        (732) 616-3371\n120                                   Liberty Antiques       ...        (908) 581-6987\n121                               Johnson Estate Sales       ...        (201) 259-0442\n122                               Buy-Gone Trading Co.       ...        (201) 665-8208\n123                      Elite Auctions &amp; Estate Sales       ...        (732) 751-1112\n124                                  The Butler Did It       ...        (908) 892-8133\n125                       Drama Mama Home Estate Sales       ...        (862) 400-2081\n126                          New Jersey Gold Resources       ...                   N\/A\n127                                          Lyrix Inc       ...        (973) 632-1600\n128                           Home Ready Services, LLC       ...        (908) 370-3062\n129                      Bygone Days Estate Sales, LLC       ...        (973) 857-9069\n130                                 Fourty Fifty Sixty       ...        (973) 341-7891\n131                                       True Salvage       ...        (973) 970-5400\n132                      Ina's Antiques &amp; Estate Sales       ...        (908) 578-4118\n133                    Caring Transitions Jersey Shore       ...        (732) 681-0054\n134                          ENCORE ESTATE &amp; TAG SALES       ...        (973) 220-4611\n135                                           Ajtrains       ...        (732) 859-1606\n136                   M.T. House Estate &amp; Moving Sales       ...        (973) 865-1173\n137                                       WCL Antiques       ...        (201) 739-3173\n138                                      Kens Antiques       ...        (732) 306-2717\n139                                 Lee Dowdy Antiques       ...        (201) 650-7208\n140                              Garage Sale Goddesses       ...        (201) 612-8510\n141                                 M &amp; J Estate Sales       ...        (908) 956-4284\n142                                     Granny's Attic       ...        (201) 632-0102\n143                              Red Barn Estate sales       ...        (201) 481-5428\n144                             D&amp;r Estate &amp; Tag Sales       ...        (201) 573-1009\n145                           Always Remember When LLC       ...        (347) 244-1591\n\n[146 rows x 4 columns]\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved organizing data that I am pulling and saving to CSV <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You can use pandas to do that. Collect all the data into a dataframe, then just write the dataframe to file. import pandas as pd import requests import bs4 root_url=&#8221;https:\/\/www.estatesales.net&#8221; url_list=[&#8216;https:\/\/www.estatesales.net\/companies\/NJ\/Northern-New-Jersey&#8217;] results = pd.DataFrame() for url in url_list: response = requests.get(url) soup = bs4.BeautifulSoup(response.text, &#8216;html.parser&#8217;) companies = soup.find_all(&#8216;app-company-city-view-row&#8217;) for company in companies: try: link &#8230; <a title=\"[Solved] organizing data that I am pulling and saving to CSV\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\" aria-label=\"More on [Solved] organizing data that I am pulling and saving to CSV\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[2677,349,2182,2463,760],"class_list":["post-13973","post","type-post","status-publish","format-standard","hentry","category-solved","tag-export-to-csv","tag-python","tag-scrapy","tag-screen-scraping","tag-web-scraping"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] organizing data that I am pulling and saving to CSV - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] organizing data that I am pulling and saving to CSV - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You can use pandas to do that. Collect all the data into a dataframe, then just write the dataframe to file. import pandas as pd import requests import bs4 root_url=&quot;https:\/\/www.estatesales.net&quot; url_list=[&#039;https:\/\/www.estatesales.net\/companies\/NJ\/Northern-New-Jersey&#039;] results = pd.DataFrame() for url in url_list: response = requests.get(url) soup = bs4.BeautifulSoup(response.text, &#039;html.parser&#039;) companies = soup.find_all(&#039;app-company-city-view-row&#039;) for company in companies: try: link ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-05T21:17:50+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] organizing data that I am pulling and saving to CSV\",\"datePublished\":\"2022-10-05T21:17:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\"},\"wordCount\":46,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"export-to-csv\",\"python\",\"scrapy\",\"screen-scraping\",\"web-scraping\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\",\"name\":\"[Solved] organizing data that I am pulling and saving to CSV - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-05T21:17:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] organizing data that I am pulling and saving to CSV\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] organizing data that I am pulling and saving to CSV - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] organizing data that I am pulling and saving to CSV - JassWeb","og_description":"[ad_1] You can use pandas to do that. Collect all the data into a dataframe, then just write the dataframe to file. import pandas as pd import requests import bs4 root_url=\"https:\/\/www.estatesales.net\" url_list=['https:\/\/www.estatesales.net\/companies\/NJ\/Northern-New-Jersey'] results = pd.DataFrame() for url in url_list: response = requests.get(url) soup = bs4.BeautifulSoup(response.text, 'html.parser') companies = soup.find_all('app-company-city-view-row') for company in companies: try: link ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/","og_site_name":"JassWeb","article_published_time":"2022-10-05T21:17:50+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] organizing data that I am pulling and saving to CSV","datePublished":"2022-10-05T21:17:50+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/"},"wordCount":46,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["export-to-csv","python","scrapy","screen-scraping","web-scraping"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/","url":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/","name":"[Solved] organizing data that I am pulling and saving to CSV - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-05T21:17:50+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-organizing-data-that-i-am-pulling-and-saving-to-csv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] organizing data that I am pulling and saving to CSV"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/13973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=13973"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/13973\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=13973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=13973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=13973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}