As I said somewhere else, i fixed bio and genre fields, and now I'm dealing with integrating selenium into PVD for downloading dymanic HTML content.
Reference from
this point forwardNow, I have passed the phase to parse the Awards page manually downloaded with selenium, and I'm having hard time with it. I have fixed the code to parse the page, and it successfuly parse it as you can see here:
(12/21/2024 10:24:56 PM) Parsed Event: Ariel Awards, Mexico
(12/21/2024 10:24:56 PM) Parsed Award: Golden Ariel
(12/21/2024 10:24:56 PM) Parsed Category: Best Picture (Mejor Película)
(12/21/2024 10:24:56 PM) Parsed Recipient: Roma
(12/21/2024 10:24:56 PM) Parsed Year: 2019
(12/21/2024 10:24:56 PM) Parsed Won: True
(12/21/2024 10:24:56 PM) Before calling AddAward with parameters:
(12/21/2024 10:24:56 PM) Event: Ariel Awards, Mexico
(12/21/2024 10:24:56 PM) Award: Golden Ariel
(12/21/2024 10:24:56 PM) Category: Best Picture (Mejor Película)
(12/21/2024 10:24:56 PM) Recipient: Roma
(12/21/2024 10:24:56 PM) Year: 2019
(12/21/2024 10:24:56 PM) Won: True
(12/21/2024 10:24:56 PM) AddAward executed successfully.
(12/21/2024 10:24:56 PM) IMDb People Awards added Event=Ariel Awards, Mexico, Award= Golden Ariel, Category=Best Picture (Mejor Película), Recipient=Roma, Year=2019, Won=True
(12/21/2024 10:24:56 PM) Added Award to Database: Event=Ariel Awards, Mexico, Award= Golden Ariel, Category=Best Picture (Mejor Película), Recipient=Roma, Year=2019, Won: True
But for some reason the value is not populated/displayed in PVD. So I thought I'll create custom memo field "IMDb People Awards" to populate there the value to check what it looks like, only to realize no custom field is visible in PVD's People section???
Is it possible at all to add custom fields in People section?
I manually put the value in the field (added to my dark people skin), but when I exit edit mode, it's not displayed. When I enter edit mode, it's there. If I restart PVD value dissappears from the custom field.
Anyway, does anyone know looking at the log, why this properly parsed award wouldn't populate to field although reported that it did?
Here's whole function (I even added some extra logging around adding value to the field in order to see what is going on, but to no avail - everything looks perfect yet value is not there):
Function CustomBoolToStr(Value: Boolean): String;
Begin
If Value Then
Result := 'True'
Else
Result := 'False';
End;
Function ParsePage_IMDBPeopleAWARDS(HTML: String): Cardinal;
Var
curPos, endPos: Integer;
ItemList, Event, Award, Category, Recipient, Year: String;
AValue: String; // Declaring AValue as a String
Won: Boolean;
FailSafe: Integer; // To prevent infinite loops
Begin
LogMessage('Function ParsePage_IMDBPeopleAWARDS BEGIN=====================||');
try
Result := prFinished;
// Log the initial HTML snippet being parsed
LogMessage('Initial HTML snippet: ' + Copy(HTML, 1, 500));
// Find the position of the Awards title
curPos := Pos('<h1 class="ipc-title__text">Awards</h1>', HTML);
If curPos > 0 Then Begin
// Find the position of the Awards section
curPos := PosFrom('<section class="ipc-page-section ipc-page-section--base">', HTML, curPos);
End;
If curPos > 0 Then Begin
// Find the end position of the Awards section
endPos := PosFrom('</section>', HTML, curPos);
If endPos = 0 Then endPos := Length(HTML);
If (curPos > 0) AND (endPos > curPos) Then Begin
// Extract the Awards block
ItemList := Copy(HTML, curPos, endPos - curPos);
// Extract and log the event name
curPos := PosFrom('<h3 class="ipc-title__text">', ItemList, 1);
If curPos > 0 Then Begin
curPos := PosFrom('>', ItemList, curPos) + 1;
endPos := PosFrom('</span>', ItemList, curPos);
Event := Copy(ItemList, curPos, endPos - curPos);
Event := Trim(Event);
// Remove the <span> tag
Event := Copy(Event, Pos('>', Event) + 1, Length(Event));
LogMessage('Parsed Event: ' + Event);
End Else LogMessage('Error: Event title div not found.');
// Parse each award item manually
curPos := PosFrom('<li class="ipc-metadata-list-summary-item sc-15fc9ae6-1 gQbMPJ" data-testid="list-item"', ItemList, 1);
FailSafe := 0; // Initialize fail-safe counter
While (curPos > 0) And (FailSafe < 10) Do Begin
// Extract and log the award name
curPos := PosFrom('<span class="ipc-metadata-list-summary-item__tst">', ItemList, curPos);
If curPos > 0 Then Begin
curPos := PosFrom('>', ItemList, curPos) + 1;
endPos := PosFrom('</span>', ItemList, curPos);
Award := Copy(ItemList, curPos, endPos - curPos);
LogMessage('Parsed Award: ' + Award);
// Extract and log the category name
curPos := PosFrom('<span class="ipc-metadata-list-summary-item__li awardCategoryName"', ItemList, curPos);
If curPos > 0 Then Begin
curPos := PosFrom('>', ItemList, curPos) + 1;
endPos := PosFrom('</span>', ItemList, curPos);
Category := Copy(ItemList, curPos, endPos - curPos);
LogMessage('Parsed Category: ' + Category);
// Extract and log the recipient name
curPos := PosFrom('<a class="ipc-metadata-list-summary-item__li ipc-metadata-list-summary-item__li--link"', ItemList, curPos);
If curPos > 0 Then Begin
curPos := PosFrom('>', ItemList, curPos) + 1;
endPos := PosFrom('</a>', ItemList, curPos);
Recipient := Copy(ItemList, curPos, endPos - curPos);
LogMessage('Parsed Recipient: ' + Recipient);
// Extract and log the year
curPos := PosFrom('<a class="ipc-metadata-list-summary-item__t"', ItemList, curPos);
If curPos > 0 Then Begin
curPos := PosFrom('>', ItemList, curPos) + 1;
endPos := PosFrom(' ', ItemList, curPos); // Find the space after the year
Year := Copy(ItemList, curPos, endPos - curPos);
Year := Trim(Year);
LogMessage('Parsed Year: ' + Year);
End Else LogMessage('Error: Year not found.');
// Determine if the award was won
Won := Pos('Winner', ItemList) > 0;
If Won Then
LogMessage('Parsed Won: True')
Else
LogMessage('Parsed Won: False');
// Construct the AValue string
AValue := 'Event=' + Event + ', Award=' + Award + ', Category=' + Category + ', Recipient=' + Recipient + ', Year=' + Year + ', Won=' + CustomBoolToStr(Won);
// Log the parameters before calling AddAward
LogMessage('Before calling AddAward with parameters:');
LogMessage('Event: ' + Event);
LogMessage('Award: ' + Award);
LogMessage('Category: ' + Category);
LogMessage('Recipient: ' + Recipient);
LogMessage('Year: ' + Year);
LogMessage('Won: ' + CustomBoolToStr(Won));
// Add the award to the database with error handling
try
AddAward(Event, Award, Category, Recipient, Year, Won);
LogMessage('AddAward executed successfully.');
except
Begin
LogMessage('Exception encountered in AddAward');
Result := prError;
End;
end;
// Populate the custom field with AValue
AddCustomFieldValueByName('IMDb People Awards', AValue);
LogMessage('IMDb People Awards added ' + AValue)
// Log the action of adding the award
If Won Then
LogMessage('Added Award to Database: Event=' + Event + ', Award=' + Award + ', Category=' + Category + ', Recipient=' + Recipient + ', Year=' + Year + ', Won: True')
Else
LogMessage('Added Award to Database: Event=' + Event + ', Award=' + Award + ', Category=' + Category + ', Recipient=' + Recipient + ', Year=' + Year + ', Won: False');
End Else LogMessage('Error: Recipient not found.');
End Else LogMessage('Error: Category not found.');
End Else LogMessage('Error: Award not found.');
// Move to the next item
curPos := PosFrom('<li class="ipc-metadata-list-summary-item sc-15fc9ae6-1 gQbMPJ" data-testid="list-item"', ItemList, curPos + 1);
End;
End Else LogMessage('Error: Invalid endPos or curPos for Awards section');
End Else LogMessage('Error: Awards section not found');
except
Begin
LogMessage('Exception encountered');
Result := prError;
End;
end;
LogMessage('Function ParsePage_IMDBPeopleAWARDS END=====================||');
Result := prFinished;
End;
//BlockClose