[英]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.