Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JSoup(java)正确解析数据_Java_Parsing_Jsoup - Fatal编程技术网

如何使用JSoup(java)正确解析数据

如何使用JSoup(java)正确解析数据,java,parsing,jsoup,Java,Parsing,Jsoup,我想使用JSoup(java)从这个HTML(公司名称、位置、工作描述等)解析数据。当我尝试迭代工作列表时,我被卡住了 从HTML中提取是我想要迭代并从中提取数据的许多“JOBLISTING”div之一。我就是无法处理如何迭代特定的div对象。很抱歉这个noob问题,但也许有人可以帮助我谁已经知道该使用哪个函数。选择 <div class="between_listings"><!-- local.spacer --></div> <div id="j

我想使用JSoup(java)从这个HTML(公司名称、位置、工作描述等)解析数据。当我尝试迭代工作列表时,我被卡住了

从HTML中提取是我想要迭代并从中提取数据的许多“JOBLISTING”div之一。我就是无法处理如何迭代特定的div对象。很抱歉这个noob问题,但也许有人可以帮助我谁已经知道该使用哪个函数。选择

<div class="between_listings"><!-- local.spacer --></div>

<div id="joblisting-2944914" class="joblisting listing-even listing-even company-98028 " itemscope itemtype="http://schema.org/JobPosting">


<div class="company_logo" itemprop="hiringOrganization" itemscope itemtype="http://schema.org/Organization">
     <a href="/stellenangebote-des-unternehmens--Delivery-Hero-Holding-GmbH--98028.html" title="Jobs Delivery Hero Holding GmbH" itemprop="url">
       <img src="/upload_de/logo/D/logoDelivery-Hero-Holding-GmbH-98028DE.gif" alt="Logo Delivery Hero Holding GmbH" itemprop="image" width="160" height="80" />
     </a>
</div>


<div class="job_info">


<div class="h3 job_title">
   <a id="jobtitle-2944914" href="/stellenangebote--Junior-Business-Intelligence-Analyst-CRM-m-f-Berlin-Delivery-Hero-Holding-GmbH--2944914-inline.html?ssaPOP=204&ssaPOR=203" title="Arbeiten bei Delivery Hero Holding GmbH" itemprop="url">
      <span itemprop="title">Junior Business Intelligence Analyst / CRM (m/f)</span>
   </a>
</div>

<div class="h3 company_name" itemprop="hiringOrganization" itemscope itemtype="http://schema.org/Organization">

    <span itemprop="name">Delivery Hero Holding GmbH</span>

</div>

</div>




<div class="job_location_date">

    <div class="job_location target-location">
         <div class="job_location_info" itemprop="jobLocation" itemscope itemtype="http://schema.org/Place">


            <div class="h3 locality" itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
                  <span itemprop="addressLocality"> Berlin</span>
            </div>


            <span class="location_actions">
                <a href="javaScript:PopUp('http://www.stepstone.de/5/standort.html?OfferId=2944914&ssaPOP=203&ssaPOR=203','resultList',800,520,1)" class="action_showlistingonmap showlabel" title="Google Maps" itemprop="maps">
                   <span class="location-icon"><!-- --></span>
                   <span class="location-label">Google Maps</span>
                </a>
            </span>

          </div>
       </div>

       <div class="job_date_added" itemprop="datePosted"><time datetime="2014-07-04">04.07.14</time></div>
</div>


<div class="job_actions">


</div>

</div>
<div class="between_listings"><!-- local.spacer --></div>

谢谢大家!

那么您的Jsoup文档是对的?如果css类
作业列表
不出现在其他任何地方,那么它看起来就很容易了

Document document = Jsoup.parse(new File("d:/bla.html"), "utf-8");
Elements elements = document.select(".joblisting");
for (Element element : elements) {
    Elements jobTitleElement = element.select(".job_title span");
    Elements companyNameElement = element.select(".company_name spanspan[itemprop=name]");
    String companyName = companyNameElement.text();
    String jobTitle = jobTitleElement.text();

    System.out.println(companyName);
    System.out.println(jobTitle);
}
我不知道为什么属性
[itemprop*=“name\”]
选择器找不到跨度(进一步阅读:)


明白了:span[itemprop=name]没有任何引号或转义符。其他属性或值也可以用于获得更具体的选择。

欢迎使用SO。你能在问题中加入你试过的代码吗?对不起,我无法正确格式化。谢谢你的热烈欢迎<代码>文件输入=新文件(“C:/Talend/workspace/WEBCRAWLER/output/keywords_SOA.txt”);//将文件加载到extraction1 Document ParseResult=Jsoup.parse中(输入“UTF-8”http://example.com/"); Elements jobListingElements=ParseResult.select(“.joblisting”);对于(Element jobListingElement:jobListingElements){jobListingElement.select(“.companyName span[itemprop=\“name\”]);//其他元素属性System.out.println(jobListingElements);我不明白为什么这不起作用。
Elements jobListingElements=ParseResult.select(“.jobListingElements”);对于(元素jobListingElement:jobListingElements){Elements e1=jobListingElement.select(“.companyName span[itemprop=\“name\”]);//其他元素属性System.out.println(e1.text())
非常感谢您的快速回答!我为我的学习缓慢提前道歉,但让我向您解释我的目标。也许您可以帮助我举一个具体的例子,从中我可以看到前进的方向。提前谢谢您!您帮了我很多!它似乎吞没了我的解释。我想提取具体的v变量(例如公司名称、职务等)并将其导入SQL-DB(稍后)。您能给我一个如何使用代码的示例吗?
span[itemprop=\“Name\”]
我没有得到这个部分。我尝试了这个,这对我来说很愚蠢=)
File input=new Elements jobListingElements=ParseResult.select(“.jobling”);for(Element jobListingElement:jobListingElements){jobListingElement.select(“.companyName span[itemprop=\'name\']”);System.out.println(jobListingElements)
更新了我的答案..不要使用属性选择器。我没有尝试就写了答案。不知怎的,jsoup没有找到属性的范围。工作很有魅力,谢谢。现在我必须弄清楚如何将它写入我的本地MS-SQL服务器。我想我会在几个小时后回来,哈哈。我喜欢这个页面。不能给你upv不过还没有
Document document = Jsoup.parse(new File("d:/bla.html"), "utf-8");
Elements elements = document.select(".joblisting");
for (Element element : elements) {
    Elements jobTitleElement = element.select(".job_title span");
    Elements companyNameElement = element.select(".company_name spanspan[itemprop=name]");
    String companyName = companyNameElement.text();
    String jobTitle = jobTitleElement.text();

    System.out.println(companyName);
    System.out.println(jobTitle);
}