I'm trying to scrape the following html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>click.com.cn</title>
<script >
window.location.href='weixin://dl/business/?t=111111'
</script>
</head>
<body>
</body>
</html>
since weixin is a custom protocol the browser cannot navigate to this website.
However it also makes the puppeteer page to get stuck on screenshot request .
I have tried to intercept this weixin:// request but have noticed that the request interceptor intercepts only http/s requests
my code :
await page.setRequestInterception(true);
page.on("request", async (request: Request) => {
const url = request.url();
// request.abort etc...
}
Is there an option in puppeteer or in Chrome DevTools Protocol to intercept all kind of protocols .
Also tried to override the window.location.href property but it failed.
I am trying to retrieve the output from the a URL using XMLHTTP GET:
The output in the browser when I hit the url directly is the following:
{
"Titles": {
"resultCount": 37680,
"moreResources": true
}
}
The ASP code on test.asp I am using is:
<%#language=JScript%>
<%
var objSrvHTTP;
objSrvHTTP = Server.CreateObject ("Msxml2.ServerXMLHTTP.6.0");
objSrvHTTP.open ("GET","http://someipaddress:8080/Publisher/Titles/Paging/0,0,tc?output=json", false);
objSrvHTTP.send ();
Response.ContentType = "application/json";
Response.Write (objSrvHTTP.responseText);
%>
The results displayed in browser from hitting test.asp is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>something</title>
</head>
<body>
{
"Titles": {
"resultCount": 37698,
"moreResources": true
}
}
</body>
</html>
I am looking to have just the data between the body tags returned, or even better just the value for "resultCount". Any help would be much appreciated.
You need to remove the HTML markup, when reading JSON data it should be nothing but valid JSON in the request response.
I am trying to implement Ooyala's player in my code and I was told that if I wanted to use buttons to switch the content of the video player then I should use the setEmbedCode function but the examples they have on their site aren't very clear.
What I want to have happen is to simply have a link that when clicked will change the video to a different URL/embed code. I've tried using the 'setQueryStringParameters'
document.getElementById('video-player'+pageNum).setQueryStringParameters({embedCode:videoURL})
All I get with that is a:
'is not a function message.'
var url = 'http://player.ooyala.com/player.js?embedCode='+videoURL+'&targetReplaceId=video-player'+pageNum+'';
var tempScript = document.createElement('script');
tempScript.type = 'text/javascript';
tempScript.src = url;
When I call this it creates the video player just fine, but I'm not sure how to change the embed code once it's created.
Check this sample code from ooyala site. "SwitchMovie" will play different video with different embedcode.
http://demo.ooyala.com/product-demos/playerScripting-demo.html
document.getElementById('player').setQueryStringParameters({embedCode:'8wNTqa-6MkpEB1c7fNGOpoSJytLptmm9',hide:'share,fullscreen'})
UPDATE:
The following code is working perfect for me. Try it, as I mentioned in my comments below you need to have a callback function if you need to interface with the player.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Swap Video</title>
</head>
<body>
<script src="http://player.ooyala.com/player.js?callback=receiveOoyalaEvent&playerId=player&width=480&height=360&embedCode=llMDQ6rMWxVWbvdxs2yduVEtSrNCJUk1&version=2"></script>
<script>
function receiveOoyalaEvent(playerId, eventName, eventArgs) {
}
</script>
<br><br>
<button onclick="document.getElementById('player').setQueryStringParameters({embedCode:'8wNTqa-6MkpEB1c7fNGOpoSJytLptmm9',hide:'share,fullscreen'})">Switch Movie</button>
</body>
</html>
I have an HTML page that is right-to-left. When I don't use any doctype, my numbers are in Arabic/Persian, but when I use strict mode they turn to English.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
Before adding doctype:
After adding doctype:
also I added these meta tags to my page:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="fa" />
So how can I view Arabic numbers in a page with strict doctype (in IE because Firefox doesn't show Arabic numbers anyway)?
here is a little javascript code that converts a 1234 string to ١٢٣٤ string
var map =
[
"&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
"&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
];
function getArabicNumbers(str)
{
var newStr = "";
str = String(str);
for(i=0; i<str.length; i++)
{
newStr += map[parseInt(str.charAt(i))];
}
return newStr;
}
You can convert English digits to Persian digits using this JavaScript code in your template:
<script type="text/javascript">
var replaceDigits = function() {
var map = ["&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;","&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"]
document.body.innerHTML = document.body.innerHTML.replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map[$0]});
}
window.onload = replaceDigits;
</script>
In case you need to replace some English to Arabic numerals and not the whole HTML, pass the number you need to this function.
function toArabicNumeral(en) {
return ("" + en).replace(/[0-9]/g, function(t) {
return "٠١٢٣٤٥٦٧٨٩".slice(+t, +t+1);
});
}
Assuming you want an XHTML 1.0 Strict document:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa" dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Title here</title>
</head>
<body>
<p>Text here</p>
</body>
</html>
Here's an equivalent HTML 4.01 Strict document:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="fa" dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Title here</title>
</head>
<body>
<p>Text here</p>
</body>
</html>
Here's an equivalent HTML5 page, just for comparison purposes.
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8" />
<title>Title here</title>
</head>
<body>
<p>Text here</p>
</body>
</html>
It is very simple to view Arabic/Persian numbers in a HTML page.
I solved the same problem by changing the font name,
In my case I want to display the same character to all users
you can choose a font that contains Arabic-Hndi digits and import it using the css ( #font-face ) then simply use it,
This works fine for all major browsers (IE .. Firefox .. Chrome)
look at this result
here is the full code of the page:
<html>
<head>
</head>
<body>
<style type="text/css">
#font-face {
font-family: ArabicTwo_Bold;
src: url( ArabicTwo_Bold.eot);
}
#font-face {
font-family: ArabicTwo_Bold;
src: url( ArabicTwo_Bold.ttf);
}
div , input {
font-family: ArabicTwo_Bold;
}
</style>
<input type='text' value='هذا نص هندي 123456 ' />
<div> هذا نص هندي 123456 </div>
</body>
</html>
firefox default render number to latin
for change this setting go to addressbar of Firefox and type about:config
this page is advanced setting of firefox
find this line "bidi.numeral" and double click on it
if set value to "1" firefox for render text look at context. if text is persian render number to persian.
if set value to "4" alwase render digit number to persian
try this , hope helps you ;)
between and
<script language="JavaScript" type="text/javascript">
var replaceDigits = function() {
var map =
[
"&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
"&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
]
document.body.innerHTML =
document.body.innerHTML.replace(
/\d(?=[^<>]*(<|$))/g,
function($0) { return map[$0] }
);
}
</script>
then in end of body tag insert this :
<script type="text/javascript">
window.onload = replaceDigits
</script>
This works for me, regardless of the text direction (in Chrome, Safari, Firefox and Opera):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body { direction: rtl; }
</style>
</head>
<body>
۴۲
</body>
</html>
(Omitted the content-language since that isn’t necessary here.)
If you use persian fonts like 'BNazanin' and write :
http-equiv="Content-Type" content="text/html; charset=UTF-8"
and http-equiv="Content-Language" content="fa" in meta tags.
You can then see the numbers in persian.
and if you use lang='En' in some tags in your html page the numbers in that tag will be displayed in english.
var map_format_arabic = ["&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;", "&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"];
$.each( $('.format_arabic'), function () {
var n=$(this).text().replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map_format_arabic[$0]});
$(this).html(n);
});
This code supports one or multiple digits of an English number which can be converted to Arabic number:
function toArabicNumber(enNum) {
if(isNaN(enNum) || enNum == null){ // Check if not a number or null
return enNum;
}
if(typeof enNum == 'string'){ // if it is a string(number) convert it to number
enNum = Number(enNum);
}
if(enNum < 10){
return "٠١٢٣٤٥٦٧٨٩".substring(enNum, enNum+1);
}
else {
let result = "";
enNum = enNum + ""; // convert number to string
for(let i = 0; i < enNum.length; i++){
let num = Number(enNum[i]); // convert digit by digit to number
result = result + "٠١٢٣٤٥٦٧٨٩".substring(num, num+1);
}
return Number(result);
}
}
just specify a persian font like 'B yekan' to them.
all troubleshoots will be solved.
I am loading the values coming from database via a json object using java struts,
but the values are not populating in my extjs grid: I keep getting an empty grid.
I have included my code below.
home.jsp
A button will be there on this page. On clicking the getvalues.jsp should come.
In getvalues.jsp an extgrid should be presen with the content coming from database
<%# page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="getvalues.do">
<input type="submit"></input>
</form>
</body>
</html>
Below is my Java code. I am populating a JSON object with the values from my database.
public class Json extends Action {
#Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
// TODO Auto-generated method stub
ArrayList<Employee> emp=new ArrayList<Employee>();
Myservice serve=new Myservice();
emp=serve.getemployeesservice();
Iterator<Employee> empitr=emp.iterator();
JSONArray json=new JSONArray();
JSONObject JSONobj=new JSONObject();
while(empitr.hasNext()){
JSONObject jobj=new JSONObject();
Employee empl=new Employee();
empl=empitr.next();
jobj.put("empid",empl.getEmpid());
jobj.put("empname",empl.getEmpname());
json.add(jobj);
}
JSONobj.put("employee",json);
System.out.println(JSONobj.toString());
return mapping.findForward("success");
}
}
getvalues.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="css/ext-all.css">
<script type="text/javascript" src="js/ext-base.js"></script>
<script type="text/javascript" src="js/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
var store=new Ext.data.JsonStore({
proxy:new Ext.data.HttpProxy({
url:'http://localhost:8080/JsonExample/getvalues.do'
}),
reader:new Ext.data.JsonReader({
root:'employee',
fields:['empid','empname']
})
});
store.load();
var recs=store.getRange();
alert(recs.length);
var grid = new Ext.grid.GridPanel({
title:'employee information',
columns: [{
header:"employeeid",
width:100,
dataIndex:'empid',
sortable:true
},{
header:"employeename",
width:100,
dataIndex:'empname',
sortable:true
}],
store: store,
width:300,
height:300,
renderTo:Ext.getBody()
});
});
</script>
</head>
<body>
hi
</body>
</html>
But the values are not being populated for some reason. Please help me solve this issue.
Thanks in advance!
I'm not good at Java. But, I suspect, your JSON list is not sent to client, you are just printing, but not including it in response.