English 中文(简体)
简单 4. 通过页源进一步搜索
原标题:Getting simpleML to search further down through the page source

I m succeeding with reading this site using simpleML in processing and getting the first username (which is babesmcphee) but I don t get the second username (which is JohnCMayer) or third, fourth, and so on. I m not sure that I m doing it right with the Strings or html.indexOf, I was thinking of doing a for loop and putting the usernames in an array.

我的守则如下:

import simpleML.*;

void setup () {
 HTMLRequest req = new HTMLRequest(this,"http://tweetingtoohard.com/top");
req.makeRequest();
}

void netEvent(HTMLRequest answer) {
  String html = answer.readRawSource();    
  String link_filter = "/u/";  
  int first_link_start = html.indexOf(link_filter);  
  String link_filter_stop = "</a>";  
  int first_link_end = html.indexOf(link_filter_stop, first_link_start+3);  
  String real_link_end_filter = """;  
  int real_link_end = html.indexOf(real_link_end_filter, first_link_start);   
  String first_link = html.substring(first_link_start+3,real_link_end);  
  println(first_link);  
}

谢谢!

最佳回答

“回答”包含整页,因此,你必须实施一个获得所有名字的通道。

与此类似:

public void netEvent(HTMLRequest answer) {
  String html = answer.readRawSource();

  int from = 0;
  int pos;
  while ((pos = html.indexOf("/u/", from)) != -1) {
    int end = html.indexOf(""", pos);
    System.out.println(html.substring(pos + 3, end));
    from = html.indexOf("</a>", pos + 3);
  }
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签