2016-06-28 12 views
1

こんにちはJavaの専門家 "div id"の下に情報が隠されている特定のURLアドレスからデータを抽出しようとしています。私のURLクエリページは次のようになります:DIV IDの下に隠された値を抽出する

私は自分のクエリとしてペプチドシーケンスを与えています。そして、 "Search Dataset"ボタンをクリックして結果をテーブルとして表示します。

しかし、「ページソースを表示」して結果をHTMLとして表示しようとしていて、そのテーブルが表示されませんでした。

「放火魔」を使用した後、私はHTMLでそのテーブルを参照することができ、それは次のようになります。

[![[]ここに画像の説明を入力2] [2]

データを取得するためには、私のクエリのために、私は単純なJavaスクリプトを書いた:

package retrieve.information; 
import java.io.IOException; 

import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 

public class DemoExtractHidenHtml { 
    public static void main(String[] args) { 
     Document document; 
     try { 
      document = Jsoup.connect("http://example.com/xyz_proxi.jsp#{\"searched_button\":\"datasets\",\"peptide\":\"NLAVSQVVHK\"}").userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21").get(); 
      Element dataset = document.select("td.table[datasets]_row[0]_column[1]").first(); 
      System.out.println(dataset); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

    } 

} 

そして、もちろん、それは私のために働いていないと、私は次のエラーを取得しています:

Exception in thread "main" org.jsoup.select.Selector$SelectorParseException: Could not parse query 'td.table[datasets]_row[0]_column[1]': unexpected token at '_row[0]_column[1]' 
at org.jsoup.select.QueryParser.findElements(QueryParser.java:196) 
at org.jsoup.select.QueryParser.parse(QueryParser.java:65) 
at org.jsoup.select.QueryParser.parse(QueryParser.java:39) 
at org.jsoup.select.Selector.<init>(Selector.java:84) 
at org.jsoup.select.Selector.select(Selector.java:106) 
at org.jsoup.nodes.Element.select(Element.java:286) 
at retrieve.information.DemoExtractHidenHtml.main(DemoExtractHidenHtml.java:14) 

誰もがこの問題を克服する方法を知っており、私はJavaの初心者です。

答えて

1

こんにちは、私はセレンを使用してその問題を解決してきたが、以下のように使用します。だから私の問題の解決策:

package extract.data; 
import java.util.Scanner; 
import java.util.regex.Matcher; 
import java.util.regex.Pattern; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class ExtractDataDynamic { 
private static Scanner kb; 

public static void main(String[] args) { 
    // TODO Auto-generated method stub 
    kb = new Scanner(System.in); 
    String userpepseq; 
    userpepseq = kb.nextLine(); 
    if (userpepseq.trim().isEmpty()){ 
     System.out.println("User didn't input any value!"); 
    } else { 
     if (Pattern.matches("[a-zA-Z]+", userpepseq) == true) { 
      WebDriver drivermassid = new FirefoxDriver(); 
      drivermassid.manage().window().maximize(); 
      drivermassid.get("http://exmaple.com/xyz_proxi.jsp#{\"searched_button\":\"datasets\",\"peptide\":\""+userpepseq+"\"}"); 
      //Here we are storing the value from the cell in to the string variable 
      String sCellValuemassid = drivermassid.findElement(By.xpath(".//*[@class='result']/tbody")).getText(); 
      drivermassid.quit(); 
      if (sCellValuemassid.length() > 0){ 
       String mid=""; 
       String status=""; 
       Pattern pattern = Pattern.compile("MSV\\d+\\s+\\d+\\s+"); 
       Matcher macther= pattern.matcher(sCellValuemassid); 
       while (macther.find()){ 
        mid=((macther.group()).split("\\ "))[0]; 
        status=((macther.group()).split("\\ "))[1]; 
       } 
       if (meid.length() > 0){ 
        WebDriver drivermasspro = new FirefoxDriver(); 
        drivermasspro.manage().window().maximize(); 
        drivermasspro.get("http://exmaple.com/xyz_proxi.jsp#{\"searched_button\":\"proteins\",\"peptide\":\""+userpepseq+"\"}"); 
        String sCellValuemasspro = drivermasspro.findElement(By.xpath(".//*[@class='result']/tbody")).getText(); 
        drivermasspro.quit(); 
        if (sCellValuemasspro.length() > 0){ 
         String [] proteinifo = sCellValuemasspro.split("\\n"); 
         for (int i=0;i<proteinifo.length;i++) { 
          String [] subproteinifo = proteinifo[i].split("\\ "); 
          System.out.println(mid+" "+status+" "+subproteinifo[1]); 
         } 
        } 
       } else { 
        System.out.println(" ID doesn't exist for "+userpepseq +"."); 
       } 
      } else { 
       System.out.println(userpepseq+" doesn't exist in database."); 
      } 


     } else { 
      System.out.println(userpepseq+" should not contain any number!"); 
     } 
    } 

そのテーブルBecuaseは動的であり、彼らはので、これは私のporblemを解決する方法の一つである私を発見したテーブルにデータを投入するためにJavaScriptを使用しています。 ありがとうございました

1

あなたはFirebugの中でテーブルを参照することができた場合は、そのセレクタ(CSSパス)をコピーし、

document.select(selector_str); 
document.select("#rso > div > div:nth-child(1) > div > h3 > a"); 
関連する問題