2016-11-10 3 views
0

Ich bin nicht vertraut mit HTML und Web Scraping mit schönen Suppe. Ich versuche, Titel, Gehälter, Standort und Firmennamen aus verschiedenen Stellenanzeigen zu erhalten. Dies ist mein Code so weit:In der Tat mit schönen Suppe Scrapping

URL = "http://www.indeed.com/jobs?q=data+scientist+%2420%2C000&l=New+York&start=10" 
import urllib2 
import bs4 
from bs4 import BeautifulSoup 
soup = BeautifulSoup(urllib2.urlopen(URL).read()) 
resultcol = soup.find_all(id = 'resultsCol') 
company = soup.findAll('span', attrs={"class":"company"}) 
jobs = (soup.find_all({'class': " row result"})) 

obwohl ich die Befehle haben Jobs und Unternehmen zu finden, kann ich nicht den Inhalt bekommen. Ich bin mir bewusst, dass es einen Inhalt Befehl gibt, aber keine meiner Variablen haben dieses Attribut bisher. Vielen Dank!

Antwort

1

Zuerst habe ich seach div mit einem Auftrag alle Elemente und dann suche ich Elemente in diesem div

import urllib2 
from bs4 import BeautifulSoup 

URL = "http://www.indeed.com/jobs?q=data+scientist+%2420%2C000&l=New+York&start=10" 

soup = BeautifulSoup(urllib2.urlopen(URL).read(), 'html.parser') 

results = soup.find_all('div', attrs={'data-tn-component': 'organicJob'}) 

for x in results: 
    company = x.find('span', attrs={"itemprop":"name"}) 
    print 'company:', company.text.strip() 

    job = x.find('a', attrs={'data-tn-element': "jobTitle"}) 
    print 'job:', job.text.strip() 

    salary = x.find('nobr') 
    if salary: 
     print 'salary:', salary.text.strip() 

    print '----------' 
+0

Dank! Irgendeine Idee, wie man Gehälter schabt? Hier ist, wie es ist verschachtelte: ' $ 88.305 - 146.570 $ pro Jahr ' – squidvision

+1

'x.find ('nobr')' – furas

+0

versucht, hat nicht funktioniert. – squidvision

Verwandte Themen