有没有任何方法可以使用css选择器添加名称链接中的描述



这是我在这段代码中的新代码,我得到了这样的输出

{"姓名":"Augustine T.K.James(6360(","日期":"2021年11月29日"}。詹姆斯;Co("公司"(已受到处罚,并被停职3个月,自2022年1月1日起生效,罚款5000-00令吉,费用为4000-00令吉,并在公司被评为"不合格"后,于2021年11月29日被学会纪律委员会勒令参加学会举办的审计质量提升计划课程,如2019年6月10日的监测审查报告所示,该报告详细说明了所开展审计工作的薄弱环节"}

我想把它们放在一个花括号下面,就像{"name":"XYZ";,"日期":"2021年11月29日";"描述:":"XYZ XYZ XYZ";}

package com.company;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minidev.json.JSONObject;
import org.apache.juneau.serializer.SerializeException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.apache.juneau.json.JsonSerializer;
import java.util.ArrayList;
import java.util.List;

public class Main {
public static void main(String[] args) throws SerializeException {
ArrayList<Product> name_date_list = new ArrayList<>();
ArrayList<Desc_Product> desc_list = new ArrayList<>();
ArrayList<String> combine_list = new ArrayList<>();

System.setProperty("webdriver.chrome.driver","F:\browser driver\chromedriver.exe");
WebDriver driver1 = new ChromeDriver();
driver1.get("https://www.mia.org.my/v2/surveillance/disciplinary/decisions.aspx");

for(int i = 0 ;i<8;i++){
for (int j =0;j<10;j++ ){
try {
List<WebElement> d1 = driver1.findElements(By.cssSelector("a[id*='PageContents_LVDecisions_ctrl']"));
WebElement webElementd1 = d1.get(j);
webElementd1.click();
List<WebElement> d3 = driver1.findElements(By.cssSelector("article.br5.bgaliceblue.alignjustify"));
WebElement webElementd3 = d3.get(0);
JsonSerializer descSerialization = JsonSerializer.DEFAULT_READABLE;
Desc_Product desc_product = new Desc_Product(webElementd3.getText());
String desc_json =  descSerialization.serialize(desc_product);
desc_list.add(desc_product);
//System.out.println(desc_json);

driver1.navigate().back();

} catch (IndexOutOfBoundsException e) {
}
}
//System.out.println("pressed next page");
List<WebElement> ed1 = driver1.findElements(By.cssSelector("input.dbutton"));
WebElement webElemented1 = ed1.get(4);
webElemented1.click();
}
WebDriver driver2 = new ChromeDriver();
driver2.get("https://www.mia.org.my/v2/surveillance/disciplinary/decisions.aspx");
for (int i =0 ;i<8;i++){
List<WebElement> e1 = driver2.findElements(By.cssSelector("td.widthtd75"));
List<WebElement> e3 = driver2.findElements(By.cssSelector("span[id*='PageContents_LVDecisions_ctrl']"));
for(int j = 0 ;j<10;j++){
try {

WebElement webElement1 = e1.get(j);
//                    System.out.println(webElement1.getText());
WebElement webElement3 = e3.get(j);
//                    System.out.println(webElement3.getText());

JsonSerializer jsonSerializer = JsonSerializer.DEFAULT_READABLE;
Product product = new Product(webElement1.getText(),webElement3.getText());

try {
String name_date =  jsonSerializer.serialize(product);
name_date_list.add(product);
}
catch (SerializeException e) {
e.printStackTrace();
}

}catch (Exception e){}
}
List<WebElement> e2 = driver2.findElements(By.cssSelector("input.dbutton"));
WebElement webElement = e2.get(4);
webElement.click();
}
for(int i =0; i<100;i++){
JsonSerializer jsonSerializer = JsonSerializer.DEFAULT_READABLE;
String name_date =  jsonSerializer.serialize(name_date_list.get(i));
System.out.println(name_date);
String desc_ = jsonSerializer.serialize((desc_list.get(i)));
System.out.println(desc_);
System.out.println("-----------------------------------------------");
}

}

}

描述类包com.company;

import org.apache.juneau.annotation.BeanConstructor;
public class Desc_Product {
private String description;
@BeanConstructor(properties = "description")
public Desc_Product(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
//    @Override
//    public String toString() {
//        return "Desc_Product{" +
//                "description='" + description + ''' +
//                '}';
//    }
@Override
public String toString() {
return " n" +
"description :"+ description;
}
}

产品类别

package com.company;
import org.apache.juneau.annotation.BeanConstructor;
import org.openqa.selenium.WebElement;
public class Product {
private String names;
private String dates;
private String description;
public Product() {
}
public String getNames() {
return String.valueOf(names);
}
public void setNames(String names) {
this.names = names;
}
public String getDates() {
return dates;
}
public void setDates(String dates) {
this.dates = dates;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
//
//    @BeanConstructor(properties = "names,dates,description")
//    public Product(String names, String dates, String description) {
//        this.names = names;
//        this.dates = dates;
//        this.description = description;
//    }
@BeanConstructor(properties = "names,dates")
public Product(String names, String dates) {
this.names = names;
this.dates = dates;
}
//    @BeanConstructor(properties = "names,dates,description")
//    public Product(String names, String dates,String description) {
//        this.names = names;
//        this.dates = dates;
//        this.description = description;
//    }
//    @Override
//    public String toString() {
//        return "{" +
//                "names='" + names + ''' +
//                ", dates='" + dates + ''' +
//                ", description='" + description + ''' +
//                '}';
//    }
@Override
public String toString() {
return  "name :"+names +"n"+
"dates :"+dates;
}
}

我没有访问Desc_Product或Product类的权限。无论如何,我试着重新创建你的程序。当我试图重新创建它时,我设法在每一页上打印出了描述。这是我的消遣。

你需要使用序列化程序是有原因的,还是只需要抓取页面的描述?如果你只需要描述,那么检查我链接的例子,让我知道你的想法。(我本想评论这一切,但我还没有足够的声誉来评论(

最新更新