简体   繁体   English

只有href =“#”,没有onclick(),如何在脚本中加载它?

[英]Only href=“#”, no onclick(), how do I load this in script?

I'm in the process of writing a scraper for the articles on the site https://www.welt.de . 我正在为网站https://www.welt.de上的文章编写刮板。 I'd also like to include the comments. 我也想发表评论。 However, when loading the page, not all comments are loaded automatically. 但是,加载页面时,并非所有注释都会自动加载。 Instead one has to click on a link to load more comments, until at some point, all are loaded. 取而代之的是,必须单击链接以加载更多评论,直到所有评论都加载完毕。

Eg: https://www.welt.de/finanzen/immobilien/article183878020/Bundesbank-sieht-im-Immobilienboom-ein-Stabilitaetsrisiko.html 例如: https : //www.welt.de/finanzen/immobilien/article183878020/Bundesbank-sieht-im-Immobilienboom-ein-Stabilitaetsrisiko.html

When you scroll down, there appears a surface "MEHR KOMMENTARE ANZEIGEN" (German for 'show more comments'). 向下滚动时,会出现一个表面“ MEHR KOMMENTARE ANZEIGEN”(德语为“显示更多评论”)。

This link looks like: 该链接看起来像:

<div href="#" style="text-align: center; height: 44px; cursor: pointer;">
<a style="font-size: 0.6875rem; font-family: ffmark, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-weight: 800; color: rgb(0, 57, 91); line-height: 5;">
<span style="font-size: 0.6875rem; font-family: ffmark, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-weight: 500; margin-right: 0.625rem; text-align: right; color: rgb(120, 120, 120);">
MEHR KOMMENTARE ANZEIGEN
<span style="width: 14px; height: 8px; margin: 0px 0px 0px 0.625rem; padding-top: 0px; display: inline-block; vertical-align: initial;">
<svg viewBox="0 0 15 9" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g transform="translate(-608.000000, -4318.000000)" fill="#787878">
<polygon transform="translate(615.205882, 4322.852941) rotate(-90.000000) translate(-615.205882, -4322.852941) " points="618.264706 4315.79412 611.205882 4322.85353 618.264706 4329.91176 619.205882 4328.97059 613.088824 4322.85353 619.205882 4316.73529">
</polygon>
</g>
</g>
</svg>
</span>
</span>
</a>
</div>

However, I do not know how to load this link in a script? 但是,我不知道如何在脚本中加载此链接?

I understand that href="#" is used when a link is handled by javascript and that it is bad style, as it is only used to change the appearance of the mouse, for which there are other methods. 据我了解,当用javascript处理链接时会使用href="#" ,它的样式不好,因为它仅用于更改鼠标的外观,对此还有其他方法。

But where is the onClick() method? 但是onClick()方法在哪里? Kinda dumbfoundead here... 有点在这里...

Clicking that show comments twice gives me the following urls 点击两次显示评论即可给我以下网址

https://api-co.la.welt.de/api/comments?document-id=183878020&created-cursor=2018-11-15T13:52:41.714&sort=NEWEST
https://api-co.la.welt.de/api/comments?document-id=183878020&created-cursor=2018-11-15T12:23:26.896&sort=NEWEST

Which returns the comments. 返回评论。 So just use the post id you have and keep fiddling with created-cursor until you get all the comments? 因此,只需使用您拥有的帖子ID并继续摆弄created-cursor,直到获得所有评论为止?

EDIT: Removing the creator-cursor parameter should give you all the comments 编辑:删除creator-cursor参数应该给您所有注释

https://api-co.la.welt.de/api/comments?document-id=183878020

EDIT 2: 编辑2:

As someone else mentioned, this might not be a good idea without first contacting the owner of the site. 正如其他人提到的那样,如果不先联系网站所有者,这可能不是一个好主意。

As far as finding the click handler: 至于找到点击处理程序:

If you inspect this element, you can see it has a click event handler calling something in communityweb.js: 如果检查此元素,则可以看到它具有一个click事件处理程序,该事件处理程序在communityweb.js中调用了某些内容:

在此处输入图片说明

This is almost certainly attached with javascript somewhere else (eg, document.getElementById('something').addEventListener("click", function(){ ... } ); ) 几乎可以肯定这是在其他地方用javascript附加的(例如document.getElementById('something').addEventListener("click", function(){ ... } );document.getElementById('something').addEventListener("click", function(){ ... } );

If you want, you can follow through and see the code it's calling (be sure to use the 'pretty print' feature, as it's minified): 如果需要,您可以按照以下步骤操作并查看其调用的代码(请务必使用“漂亮打印”功能,因为它已被缩小):

在此处输入图片说明

It gets complicated from there, but if you're determined enough you could step through in the debugger and see what's being called. 从那里开始,它变得很复杂,但是如果您有足够的决心,则可以逐步进入调试器并查看正在调用的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM