title: Scraping Yellowpages in R
body: <p>I am trying to scrape a list of plumbers from <a href="http://www.yellowpages.com.au" rel="nofollow noreferrer">http://www.yellowpages.com.au</a> to build a tibble.</p>
  <p>The code works fine with each section (name, phone number, email) but when I put it together in a function to build the tibble it hits an error because some don't have phone numbers or emails.</p>
  <pre><code>url &lt;- &quot;https://www.yellowpages.com.au/search/listings?clue=plumbers&amp;locationClue=Greater+Sydney%2C+NSW&amp;lat=&amp;lon=&amp;selectedViewMode=list&quot;
  
  testscrape &lt;- function(){
    webpage &lt;- read_html(url)
    
    docname &lt;- webpage %&gt;%
      html_nodes(&quot;.left .listing-name&quot;) %&gt;%
      html_text()
    
    ph_no &lt;- webpage %&gt;%
      html_nodes(&quot;.contact-phone .contact-text&quot;) %&gt;%
      html_text()
    
    email &lt;- webpage %&gt;%
      html_nodes(&quot;.contact-email&quot;) %&gt;%
      html_attr(&quot;href&quot;) %&gt;%
      as.character() %&gt;%
      str_remove_all(&quot;.*:&quot;) %&gt;%
      str_remove_all(&quot;\\?(.*)&quot;) %&gt;%
      str_replace_all(&quot;%40&quot;,&quot;@&quot;)
    
    return(tibble(docname = docname, ph_no = ph_no, email = email))
  }
  </code></pre>
  <p>Then I run the function:</p>
  <pre><code>test_run &lt;- testscrape
  test_run()
  </code></pre>
  <p>And the following errors arrive:</p>
  <pre><code>Error: Tibble columns must have compatible sizes.
  * Size 36: Existing data.
  * Size 17: Column `ph_no`.
  ℹ Only values of size one are recycled.
  Run `rlang::last_error()` to see where the error occurred.
  Called from: signal_abort(cnd)
  Browse[1]&gt; 
  </code></pre>
  <p>Which leaves it hanging.</p>
  <p>I appreciate that there are fewer phone numbers than listed plumbers so how do I create a N/A return for that line for that plumber so that the numbers align with the relevant plumbers?</p>
  <p>Thanks in advance.</p>