简体   繁体   English

JavaScript 从网站检索文本并显示在我的网站上

[英]JavaScript to retrieve text from a website and display on my site

Trying to work out how to search a website (eg https://www.fakewebsite.com/ ) for text between two stings (eg ABC text that changes from time to time XYZ ) and displays on my website.试图找出如何在网站(例如https://www.fakewebsite.com/ )中搜索两个刺痛之间的文本(例如,不时更改 XYZ 的 ABC 文本)并显示在我的网站上。 Think the following has something to do with it, but not sure how to scrape the data from the external site:认为以下与它有关,但不确定如何从外部站点抓取数据:

//Gets the part of the string inbetween the ABC and the XYZ
var part = str.substring(
    str.lastIndexOf("ABC") + 1, 
    str.lastIndexOf("XYZ")
);

Any ideas?有任何想法吗? Hope www.fakewebsite.com isn't a real site.希望www.fakewebsite.com不是真实网站。 Looking to do this with JavaScript as my site is a SharePoint site so scripting is a nightmare.由于我的站点是 SharePoint 站点,因此希望使用 JavaScript 执行此操作,因此脚本编写是一场噩梦。

Hope that I understand your request.希望我能理解您的要求。 There are a few ways to go about realising this.关于实现这一点,go 有几种方法。 In my opinion the easiest one is to try and match the text inside the requested website to regular expressions.在我看来,最简单的方法是尝试将请求网站内的文本与正则表达式匹配。 If it helps you can reach here: https://regex101.com/如果它对您有帮助,您可以到达这里: https://regex101.com/

You can do something similar to what you did, like: body.match(/(text you want)/g), this should return an array with the matches or falsey.你可以做一些类似于你所做的事情,比如:body.match(/(你想要的文本)/g),这应该返回一个包含匹配项或错误的数组。

暂无
暂无

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

相关问题 如何从其他网站提取特定的div并显示在我的网站上? - how to extract specific div from other website and display on my site? Javascript:从网站上获取元素并将其显示在我的网站上? - Javascript: Take element from website and display it on my website? 我如何使用JavaScript从其他网站检索文本? - How would I use JavaScript to retrieve text from a different website? 我需要从本地文件夹中检索所有图像(无论编号和名称如何)并将其显示在我的网站上 - I need to retrieve ALL images (regardless of number and name) from a local folder and display them on my website Javascript从网站(会员网站)提取数据 - Javascript pull data from website (member site) 是否可以使用javascript从其他网站提取文本并将其放置在其他网站中? - Is it possible to pull text from another website and place it in another site using javascript? 如何使用javascript读取文本文件并将其显示在我的网站上? - How do i use javascript to read a text file and display it on my website? 优化我的网站使用但不在我的网站上的Javascript和CSS? - Optimizing Javascript and CSS used BY my web site but not located ON my website? 使用javascript从网站获取文本 - Getting text from a website with javascript 如何创建一个 javascript 小部件来从我的 wordpress 站点加载最近的帖子并在其他站点中显示? - How to create a javascript widget to load recent posts from my wordpress site and display in other sites?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM