File tree Expand file tree Collapse file tree 3 files changed +14
-7
lines changed
Expand file tree Collapse file tree 3 files changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,14 @@ class PandaNovelParser extends Parser {
4848 }
4949
5050 customRawDomToContentStep ( webPage , content ) {
51- content . innerHTML = "<p>" + content . innerHTML . replaceAll ( "<br><br>" , "</p>\n<p>" ) + "</p>"
51+ let html = "<p>" + content . innerHTML . replaceAll ( "<br><br>" , "</p>\n<p>" ) + "</p>" ;
52+ let parsed = new DOMParser ( ) . parseFromString ( html , "text/html" ) ;
53+ while ( content . firstChild ) {
54+ content . removeChild ( content . firstChild ) ;
55+ }
56+ for ( const tag of [ ...parsed . querySelector ( "body" ) . children ] ) {
57+ content . appendChild ( tag )
58+ }
5259 }
5360
5461 extractTitleImpl ( dom ) {
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ class QidianParser extends Parser{
3838 isIncludeable : ! QidianParser . isLinkLocked ( link )
3939 } ;
4040 }
41-
41+
4242 findContent ( dom ) {
4343 return dom . querySelector ( "div.cha-content" ) ;
4444 } ;
@@ -58,10 +58,10 @@ class QidianParser extends Parser{
5858 let h = webPage . createElement ( "h3" ) ;
5959 h . textContent = json . chapterInfo . chapterName ;
6060 content . appendChild ( h ) ;
61+ let domParser = new DOMParser ( ) ;
6162 for ( let c of json . chapterInfo . contents ) {
62- let p = webPage . createElement ( "p" ) ;
63- p . innerHTML = c . content ;
64- content . appendChild ( p ) ;
63+ let parsed = domParser . parseFromString ( "<p>" + c . content + "</p>" , "text/html" ) ;
64+ content . appendChild ( parsed . querySelector ( "p" ) ) ;
6565 }
6666 }
6767
@@ -111,7 +111,7 @@ class QidianParser extends Parser{
111111
112112 // title of the story
113113 extractTitleImpl ( dom ) {
114- let title = dom . querySelector ( "div.page h2 " ) ;
114+ let title = dom . querySelector ( "div.page h1 " ) ;
115115 if ( title !== null ) {
116116 util . removeChildElementsMatchingCss ( title , "small" ) ;
117117 }
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ let QidianChatperLinkSample =
3535 <base href="https://www.webnovel.com/book/9017100806001205/King-of-Gods" />
3636</head>
3737<body">
38- <div class="page"><h2 class="pt4 pb4 oh mb4 auto_height">King of Gods <small>KOG</small></h2><div>
38+ <div class="page"><h1 class="pt4 pb4 oh mb4 auto_height">King of Gods <small>KOG</small></h2><div>
3939<ol>
4040<li class="g_col_6" data-report-eid="E10" data-bid="King of Gods" data-report-bid="9017100806001205" data-cid="30995441462068685" data-report-cid="30995441462068685">
4141 <a href="//www.webnovel.com/book/9017100806001205/30995441462068685/King-of-Gods/Young-Zhao-Feng-" class="c_000 db pr clearfix pt8 pb8 pr8 pl8">
You can’t perform that action at this time.
0 commit comments