{"id":5868,"date":"2020-01-01T19:33:31","date_gmt":"2020-01-02T00:33:31","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=5868"},"modified":"2020-01-01T22:25:25","modified_gmt":"2020-01-02T03:25:25","slug":"extracting-dates-and-waste-streams-for-the-netherlands","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=5868","title":{"rendered":"Extracting Waste Stream Collection Dates for the Netherlands"},"content":{"rendered":"<p>Yeah &#8230; mostly saving this for the regex search with a start and end flag that spans newlines because I don&#8217;t <em>really<\/em> need to know the date they collect each waste stream in the Netherlands. Although it&#8217;s cool that they&#8217;ve <em>got<\/em> five different waste streams to collect.<\/p>\n<pre>import requests\r\nimport re\r\n\r\nstrBaseURL = 'https:\/\/afvalkalender.waalre.nl\/adres\/&lt;some component of your address in the Netherlands&gt;' \r\niTimeout = 600 \r\nstrHeader = {'User-Agent': 'Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/61.0.3163.100 Safari\/537.36'}\r\n\r\n# Start and end flags for waste stream collection schedule content\r\nSTART = '&lt;ul id=\"ophaaldata\" class=\"line\"&gt;' \r\nEND = '&lt;\/ul&gt;' \r\n\r\npage = requests.get(strBaseURL, timeout=iTimeout, headers=strHeader)\r\nstrContent = page.content\r\nstrContent = strContent.decode(\"utf-8\")\r\n\r\nresult = re.search('{}(.*?){}'.format(START, END), strContent, re.DOTALL)\r\nstrCollectionDateSource = result.group(1)\r\n\r\nresultWasteStreamData = re.findall('&lt;li&gt;(.*?)&lt;\/li&gt;', strCollectionDateSource, re.DOTALL)\r\nfor strWasteStreamRecord in resultWasteStreamData:\r\n    listWasteStreamRecord = strWasteStreamRecord.split(\"\\n\")\r\n    strDate = listWasteStreamRecord[3]\r\n    strWasteType = listWasteStreamRecord[4]\r\n    print(\"On {}, they collect {}\".format(strDate.strip().replace('&lt;i class=\"date\"&gt;','').replace('&lt;\/i&gt;',''), strWasteType.strip().replace('&lt;i&gt;','').replace('&lt;\/i&gt;','')))\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Yeah &#8230; mostly saving this for the regex search with a start and end flag that spans newlines because I don&#8217;t really need to know the date they collect each waste stream in the Netherlands. Although it&#8217;s cool that they&#8217;ve got five different waste streams to collect. import requests import re strBaseURL = &#8216;https:\/\/afvalkalender.waalre.nl\/adres\/&lt;some component &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[664,883],"class_list":["post-5868","post","type-post","status-publish","format-standard","hentry","category-coding","tag-python","tag-regex"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5868"}],"version-history":[{"count":6,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5868\/revisions"}],"predecessor-version":[{"id":5874,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/5868\/revisions\/5874"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}