Я столкнулся с трудностями при получении определенного текстового шаблона из элемента HTML на моей веб-странице. Вот фрагмент HTML:
Это с моего веб-сайта, и я хочу получить его с "
Work Order 0000037282 has been reissued.
только:
0000037282
Сохраните его и используйте позже на другой странице, например номер рабочего заказа =
0000037282
Invoice 0000026791 has been credited. Credit document HO0000000033 was created.
Work Order 0000037282 has been reissued.
Это то, что я пробовал до сих пор, но безуспешно:
это из моего теста
await reissueWorkOrderConfirmationModal.ConfirmAsync();
string? workOrderNumber = await creditInvoiceModal.GetReissuedWorkOrderNumberAsync();
if (workOrderNumber != null)
{
Console.WriteLine($"Reissued Work Order Number: {workOrderNumber}");
}
else
{
Console.WriteLine("Failed to retrieve the reissued work order number.");
}
И вот что я добавил в модальном окне:
public async Task GetReissuedWorkOrderNumberAsync()
{
// Execute JavaScript in the browser context to retrieve the text of the success message elements
string successMessages = await _page.EvaluateAsync(@"() => {
const messages = Array.from(document.querySelectorAll('.alert.alert-success .row.ng-binding.ng-scope'));
return messages.map(message => message.innerText).join('|');
}");
// Define the regular expression pattern to match the Work Order number
string pattern = @"Work Order (\d+) has been reissued.";
// Use regular expression to match the pattern
Match match = Regex.Match(successMessages, pattern);
// Check if the pattern is found
if (match.Success)
{
// Extract the Work Order number from the matched groups
string workOrderNumber = match.Groups[1].Value;
return workOrderNumber;
}
// Return null if the pattern is not found
return null;
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... on-matcher
Проблема при получении числа из строки HTML с помощью средства сопоставления регулярных выражений ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Странное поведение сопоставления регулярных выражений Java в отношении отрицания через ^
Anonymous » » в форуме JAVA - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-