Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Neither of your functions <em>returns</em> anything. The default then is to return <code>None</code>, resulting in your error.</p> <p>Add <code>return</code> statements to your functions instead of printing the results. You are gathering lists of links, so you'll need to alter your code to return the lists and concatenate the two lists, or write them to the output file separately:</p> <pre><code>def jobsinghana(): site = "http://www.jobsinghana.com/jobs" hdr = {'User-Agent' : 'Mozilla/5.0'} req = urllib2.Request(site, headers=hdr) mayday = urllib2.urlopen(req) soup = BeautifulSoup(mayday) return map(str, soup.find_all('a', {'class' : 'hover'})) def modernghana(): site = "http://www.modernghana.com/GhanaHome/classifieds/list_classifieds.asp? menu_id=7&amp;sub_menu_id=362&amp;gender=&amp;cat_id=173&amp;has_price=2" hdr = {'User-Agent' : 'Mozilla/5.0'} req = urllib2.Request(site, headers=hdr) jobpass = urllib2.urlopen(req) soup = BeautifulSoup(jobpass) jobs = soup.find_all('a', href = re.compile('show_classifieds')) result = [] for a in jobs: header = a.parent.find_previous_sibling('h3').text a.string = header result.append(str(a)) return result jobsinghana_links = jobsinghana() modernghana_links = modernghana() with open('content.html', 'w') as alllinks: alllinks.write("\n".join(jobsinghana_links + modernghana_links)) </code></pre> <p>If you need to skip links you found before, you'll have to read in the links, preferably into a set, to test against when scanning again:</p> <pre><code>def read_existing(): with open('content.html') as alllinks: return {line.strip() for line in alllinks} existing = read_existing() jobsinghana_links = jobsinghana(existing) modernghana_links = modernghana(existing) </code></pre> <p>and in the two functions reading links, filter out any link already present in <code>existing</code>, using <code>if link in existing:</code> tests.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload