Commit a624e3e
authored
Support new page nav attribute changes made by SA (#1221)
* Support new page nav attribute changes made by SA
The original scrapePageDropdown method is still in place as a fallback, but the new data atributes will be used first.
See: https://forums.somethingawful.com/showthread.php?threadid=3944917&pagenumber=3#post548658773
- The tests using the updated showthread2.html fixture (testIgnoredPost and testWeirdSizeTags) are using the new data attributes: [PageNav] Using data attributes: page 17/18
- The tests with older fixtures are falling back to the select menu method: [PageNav] Using select menu fallback: page X/Y
Changes Made:
1. Updated scrapePageDropdown function
(AwfulCore/Sources/AwfulCore/Scraping/Helpers.swift:144-169):
- First attempts to read the new data-current-page and data-total-pages attributes
- Falls back to the old select menu counting method for backward compatibility
- Added logging to show which method is being used: [PageNav] Using data attributes or [PageNav] Using select menu fallback
2. Added new PageNavigationData struct and scrapePageNavigationData function
(Helpers.swift:111-142):
- Captures all four new data attributes: current-page, total-pages, base-url, and per-page
- Available for future use when you need the base URL or per-page values
3. Updated test fixture (showthread2.html):
- Replaced this file with a modern sample (taken from the same thread and roughly the same page)
- Tests confirm the new attributes are being read correctly
Test Results:
- All 60 tests pass successfully
- Logging shows the new data attributes are being used when present
- Fallback to select menu works for older fixtures without the attributes
The implementation ensures the app won't break when the site changes the inner HTML of the pages div, as warned by the admin.
* Removed print statements, removed scrapePageDropdown() fallback and solely use the new scrapePageNavigationData()1 parent 74f2539 commit a624e3e
File tree
4 files changed
+2076
-2012
lines changed- AwfulCore
- Sources/AwfulCore/Scraping
- Tests/AwfulCoreTests/Fixtures
4 files changed
+2076
-2012
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
112 | 119 | | |
113 | | - | |
| 120 | + | |
114 | 121 | | |
115 | | - | |
116 | | - | |
117 | 122 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
123 | 138 | | |
124 | | - | |
| 139 | + | |
125 | 140 | | |
126 | 141 | | |
127 | 142 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
0 commit comments