I'm scraping dynamic content with PhantomJS. I want to load this website: https://www.instagram.com/explore/tags/fun/, and click the button at the bottom of the screen "load more" to load more pictures, and save the HAR content. This code works:
var page require('webpage').create();
page.open('http://www.milliondollarhomepage.com', function(status) {
setTimeout(function(){
page.sendEvent('click', 240, 210, button='left') }, 200);
setTimeout(function(){
page.render("screensho1.png");
phantom.exit();
}, 5000);
});
It clicks a --link-- on the screen. But when I use my URL of interest, https://www.instagram.com/explore/tags/fun/ the same code with the proper coordinates won’t click the ---button---.
Any help would be much appreciated.
Positioning of elements is often relative, so I would recommend to avoid absolute click events; instead work with selectors and trigger a click event on the element:
var page = require('webpage').create();
var fs = require('fs');
var system = require('system');
var url = "https://www.instagram.com/explore/tags/fun/";
page.open(url, function(status) {
console.log("Status: " + status);
if(status === "success") {
setTimeout(
function(){
page.evaluate(
function(){document.querySelector("#react-root > section > main > article > div > div > a").click();}
);
}, 200);
setTimeout(
function(){
path = 'hardcoded.png';
page.render(path, {format: 'png', quality: '100'});
phantom.exit();
}, 1000);
}else{
phantom.exit();
}
});
Related
I am trying to create a extension in Firefox using sdk addon. What i want to do is to call an iframe inside a panel.
I have already created the extension for chrome and now i am trying to do it for firefox.
I have a facebook login in the iframe. Once i click on the sign in button the iframe just goes blank. If I log in before hand then also the extension doesnt work. It is as if it can't access the session.
Here is the code of my main.js file.
var { ToggleButton } = require('sdk/ui/button/toggle');
var panels = require("sdk/panel");
var data = require("sdk/self").data;
var {Cc, Ci} = require("chrome");
var tabs = require("sdk/tabs");
var title=tabs.activeTab.title;
var button = ToggleButton({
id: "my-button",
label: "my button",
icon: {
"16": "./logo1.png",
"32": "./logo1.png",
"64": "./logo1.png"
},
onChange: handleChange
});
var panel = panels.Panel({
width:450,
height:400,
contentURL: data.url("popup.html"),
onHide: handleHide
});
function handleChange(state) {
if (state.checked) {
panel.show({
position: button
});
}
}
function handleHide() {
button.state('window', {checked: false});
}
here is the code of my main javascript file that calls the iframe
$(document).ready(function() {
document.body.style.display = 'block';
var ur='xyz';
var frame = document.createElement('iframe');
var frame_url = 'https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/page-mod';
frame.setAttribute('width', '100%');
frame.setAttribute('height', '100%');
// frame.setAttribute('margin', '-10%');
frame.setAttribute('frameborder', 'none');
frame.setAttribute('id', 'rtmframe');
$('body').height(450).width(400);
frame.setAttribute('src', frame_url);
document.body.appendChild(frame);
$('iframe#rtmframe').load(function() {
$('#loadImg').hide();
});
});
This is not the actual link i am trying to open. Can anyone suggest what i can do differently. or point me to github code that might be doing the same thing.
i have a magnific popup being displayed dynamically but the image is rendered after the load event so i cannot get the value of the image in the open event. is there any onload event in magnific popup?
function OpenPopup(el) {
var temp = el.innerHTML;
var mysrc = $(temp).attr("src");
var isobj = $.magnificPopup.open({
items: {
src: mysrc,
onload: 'myevent()',
},
type: 'iframe',
closeOnBgClick: false,
markup: '<div class="mfp-iframe-scaler">' +
'<div class="mfp-close"></div>' +
'<iframe class="mfp-iframe" frameborder="0" onload="myevent()"></iframe>' +
'<div class="mfp-bottom-bar">' +
'<div class="mfp-title"></div>' +
'</div>' +
'</div>',
callbacks: {
beforeOpen: function () {
console.log('Start of popup initialization');
},
elementParse: function (item) {
// Function will fire for each target element
// "item.el" is a target DOM element (if present)
// "item.src" is a source that you may modify
debugger;
console.log('Parsing content. Item object that is being parsed:', item);
},
change: function () {
console.log('Content changed');
console.log(this.content); // Direct reference to your popup element
},
resize: function () {
console.log('Popup resized');
// resize event triggers only when height is changed or layout forced
},
open: function () {
console.log('Popup is opened');
debugger;
var iframe = $.magnificPopup.instance,
t = $(iframe.currItem.el[0]);
var contents = iframe.contents();
$(contents).css('max-width', '100%');
$(contents).css('max-height', '100%');
}
}
});
Not a proper solution put i added a timed event which resizes the image once it is loaded. Had to play a lot to get the perfect time so that there is no glitch.
Here is the code:
function OpenPopup(el) {
var temp = el.innerHTML;
var mysrc = $(temp).attr("src");
var isobj = $.magnificPopup.open({
items: {
src: mysrc,
},
delegate: 'a',
type: 'iframe',
closeOnBgClick: false,
});
setTimeout(setImage, 500);
};
function setImage() {
var iframe = $('.mfp-iframe');
var contents = iframe.contents();
$(contents).find('img').attr('width', '100%');
$(contents).find('img').attr('height', '100%');
}
I've been having issues trying to get Isotope to render properly.
I've tried a few different ways to get it to work, including using the imagesLoad function, to no avail.
You can view the page here: http://wpsanjose.com/#latest-posts
If you select "ALL", you'll see the proper margins appear which is what I'm after when it first pops up.
This is the code I'm using:
(function($) {
$(window).load(function() {
//Set the isotope area
var $container = $('#isotope-wrap');
//Set our items to be filtered and how to display
$container.isotope({
itemSelector: 'article',
masonry: {
columnWidth: 1
}
});
var $filterSets = $('.options'),
$filterLinks = $filterSets.find( 'a' );
$filterLinks.click(function() {
var $this = $(this);
// don't do anything if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $filterSet = $this.parents('.options');
$filterSet.find('.selected' ).removeClass('selected');
$this.toggleClass('selected');
})
// filter items when filter link is clicked
jQuery('#filters a').click(function(){
var selector = $(this).attr('data-filter');
$container.isotope({
filter: selector
});
return false;
})
});
$(".entry").hover(
function() {
$(".article-outer", this).stop().animate({top: '-1000px'},{queue: false, duration: 700});
},
function() {
$(".article-outer", this).stop().animate({top: '0px'},{queue: false, duration: 700});
});
})(jQuery);
any help would be greatly appreciated!
I am new to Titanium appcelerator programming.My doubt is button click is event is working well in first screen after that when I click that button go to second screen.Second screen consisting of one button ,when I click that button it navigates to third screen .But button click event is not working in second screen.
I wrote the same code in two screens as follows:
Please tell where I did mistake.
First Screen:
Ti.include("Files/MainScreen.js");
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
win.open();
var itemView = Titanium.UI.createView({
title:'',
backgroundImage:'splash.png',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"Files/MainScreen.js"
});
newWindow.open(win,{animated:true});
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
MainScreen.js:
Ti.include("CustomerScreen.js");
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
var image = Ti.UI.createImageView({
image:'main_screen.png'
});
win.add(image);
win.open();
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
background : "#000",
title : "",
url:"Files/CustomerScreen.js"
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
win.open();
CustomerScreen.js
var win = Titanium.UI.createWindow({
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
win.open();
Try the following code. I have created a sample application from your code. Try it out
app.js
var win = Titanium.UI.createWindow({
title:'My Window',
backgroundColor:'#cccccc'
});
var itemView = Titanium.UI.createView({
title:'Splash screen',
backgroundColor:'yellow',
height:'768',
width:'1024'
});
// Eventlistener
itemView.addEventListener('click',function(e) {
var newWindow = Ti.UI.createWindow({
background : "#000",
title : "Image View",
url:"MainScreen.js",
backgroundColor:'#cccccc',
leftNavButton:btnCancel
});
newWindow.open(win,{animated:true});
});
var btnCancel = Titanium.UI.createButton({
title:'Cancel'
});
win.add(itemView);
win.orientationModes=[Titanium.UI.LANDSCAPE_LEFT];
win.open();
MainScreen.js
var win = Ti.UI.currentWindow;
win.title = 'My Window';
var image = Ti.UI.createImageView({
backgroundColor:'red'
});
win.add(image);
var custbutton=Titanium.UI.createButton({
title:'customer',
top:200,
bottom:300,
left:90,
height:'235',
width:'235',
backgroundColor:"#000"
});
custbutton.addEventListener('click',function alertingcustomer () {
var newWindow1 = Ti.UI.createWindow({
title : "Customer screen",
url:"CustomerScreen.js",
title:'Window',
backgroundColor:'#cccccc',
modal:true
});
newWindow1.open(win,{animated:true});
});
win.add(custbutton);
CustomerScreen.js
var win = Ti.UI.currentWindow;
//Do stuff here
There are a lot of things you have to notice.
It is wrong approach include a file in another file and opening a window which has property url set to included file.
Opening a window multiple time is a wrong approach[You have written win.open() twice in the firts file, it is trying to open same window]
You're opening a window using url property, it'll be better to use Ti.UI.currentWindow property than creating a new window inside that.
I have a strange problem and i m not able to understand why it is happening.
I called a page - Remarks(say) by jquery ajax on row click of grid viw. Then i binded that page (coming in response) into a div - dvRemarks(say). This div is opening in a popup.
Pop-up window is only opening first time, which is working fine. But when i click second time, data is coming in response, But this time popup is not opening. Problem is with popup only but i don't understand why it is ?
When i again refresh the page, it again opens up Ist time only.
Below is jquery :-
jQuery(function() {
// Remarks
jQuery('#<%=dvRemarks1.ClientID %>').dialog({
autoOpen: false,
width: 600,
modal: true
});
// Remarks Link
jQuery('#lnkDialog').click(function() {
jQuery('#<%=dvRemarks1.ClientID %>').dialog('open');
return false;
});
});
Below is the function which i am calling on click :-
function Call_Ajax(id)
{
var d = new Date();
var n = d.getMilliseconds();
var parameters="id=" + id;
$.ajax({
type: "POST",
url: "Remark.aspx",
data: {id:id, n:n},
success: function(response) {
$('#<%=dvRemarks.ClientID %>').html(response);
$("#lnkDialog").click();
},
error: function() {
alert('Some problem has been occured.');
}
});
}
And below is the div - dvRemarks in which i am binding response
<div id="dvRemarks1" runat="server" style="display: none;" title="Enter Remarks">
<div id="dvRemarks" runat="server">
</div>
</div>
Thanks.
Not sure on this but give a try to below one.
jQuery(function() {
// Remarks
jQuery('#<%=dvRemarks1.ClientID %>').dialog({
autoOpen: false,
width: 600,
modal: true, //Calling destroy on close function might help
close: function() {
$(this).dialog("destroy");
}
});
// Remarks Link
jQuery('#lnkDialog').click(function() {
jQuery('#<%=dvRemarks1.ClientID %>').dialog('open');
return false;
});
});
give a try changing ajax call to
function Call_Ajax(id)
{
var d = new Date();
var n = d.getMilliseconds();
var parameters="id=" + id;
$.ajax({
type: "POST",
url: "Remark.aspx",
data: {id:id, n:n},
success: function(response) {
$('#<%=dvRemarks.ClientID %>').empty().html(response); //empty function may be of some help here
$("#lnkDialog").click();
},
error: function() {
alert('Some problem has been occured.');
}
});
}