Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/ac_scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,16 +573,21 @@ pub async fn get_sample_cases(
let mut outputs: Vec<(usize, String)> = Vec::new();

for pre_element in pre_elements {
let pre_content = pre_element.text().next().context(PARSE_ERROR)?;
let parent_element = pre_element
.parent()
.and_then(ElementRef::wrap)
.context(PARSE_ERROR)?;
let h3_element = parent_element
.select(&h3_selector)
.next()
.context(PARSE_ERROR)?;
let h3_content = h3_element.text().next().context(PARSE_ERROR)?;
let pre_content = pre_element.text().collect::<String>();
let mut h3_content: Option<String> = None;
let mut cursor = pre_element.parent();
while let Some(node) = cursor {
if let Some(parent) = ElementRef::wrap(node) {
if let Some(h3_element) = parent.select(&h3_selector).next() {
if let Some(text) = h3_element.text().next() {
h3_content = Some(text.to_string());
break;
}
}
}
cursor = node.parent();
}
let h3_content = h3_content.context(PARSE_ERROR)?;
let is_input = h3_content.contains(INPUT_HEADER);
let is_output = h3_content.contains(OUTPUT_HEADER);
if is_input {
Expand All @@ -592,15 +597,15 @@ pub async fn get_sample_cases(
.collect::<String>()
.parse()
.unwrap();
inputs.push((index, pre_content.into()));
inputs.push((index, pre_content));
} else if is_output {
let index: usize = h3_content
.chars()
.filter(|c| c.is_ascii_digit())
.collect::<String>()
.parse()
.unwrap();
outputs.push((index, pre_content.into()));
outputs.push((index, pre_content));
}
}
if let Some(target) = sample_case_id_arg {
Expand Down