while loop with image context - while-loop

This is the first time I've ever used python or written code.
I'm trying to write code that will scroll through a website and download videos before I go on a trip where I won't have internet access for many months.
I'm trying to get it to scroll down, start the video, start a download, and move onto the next video (rinse and repeat). I can get every other button to line up if I scroll slightly past, then click on the video; because the website sets the video at the center of the screen. But, I'm having trouble getting it to scroll down a variable amount. the position of the video changes based on the size of the ad that loads. I can get it to detect text that is above the link to the next video, but I don't know how to make the loop to get it to scroll down in the first place. Please help, thanks.
`
while keyboard.is_pressed('q') == False:
while pyautogui.locateOnScreen('next video.png',region=(860,1190,200,200), grayscale=True, confidence=0.9) == False:
pyautogui.scroll(-10)
#make the page scroll down a varying amount (if add or alternate video sources appear) so video window and link to next video lines up
if pyautogui.locateOnScreen('next video.png',region=(860,1190,200,200), grayscale=True, confidence=0.9) !=None:
pyautogui.press("down")
click(847,463)
#click starts video so downloader can find video file
time.sleep(7)
if pyautogui.pixel(1443, 915)[0] == 0:
click(2050,110)
#click video downloader in tool bar for drop down
time.sleep(2)
if pyautogui.locateOnScreen('download image.png', region=(1100,330,60,60), grayscale=True, confidence=0.9) !=None:
click(1556,335)
#click to start download if downloader also finds ad
time.sleep(2)
else:
click(1540,212)
#click to start download if downloader finds no ad
time.sleep(2)
if pyautogui.pixel(1443, 915)[0] == 0:
click(1088,1292)
#click to load next video
time.sleep(3)
`

Related

making a picture slider in elm, model updates triggered by loaded element

I am making a website in elm that includes a dynamic element for browsing pictures. One can click a given thumb to see the full picture in a lightbox, navigate to the next or previous picture or let the picture change automatically every three second.
By default one sees only a small selection (4 thumbs) but it is possible to previews all the thumbs by clicking on "voir toute les photos"
running example here
Each user click or tick of the clock change the underlying model, which in turn makes the browser actualize the HTML accordingly.
I am mostly satisfied with the current level of functionality except for the fact than I can't find a way to display a transition screen (or picture) while the next picture is loading.
The lightbox displays the last displayed picture while loading the next one, and transitions abruptly.
Is there a way to trigger a change in the model only when the next picture is loaded?
Or a more idiomatic way to do this sort of thing? I am quite new to elm and web development in general.
the elm code for the gallery is visible at:
https://github.com/eniac314/mairieMurol/blob/master/src/Gallery.elm
It sounds like you just need a way to know when an image is finally loaded. You can tie into the img.onload DOM event, but first you'll need a Json Decoder to pull image src attribute out of an event.
Updated to elm-0.18
onLoadSrc : (String -> msg) -> Html.Attribute msg
onLoadSrc tagger =
on "load" (JD.map tagger targetSrc)
targetSrc : JD.Decoder String
targetSrc =
JD.at [ "target", "src" ] JD.string
Now you can use that decoder to call a new ImageLoaded String action, passing the image source as a string.
img
[ src imgsrc
, onLoadSrc ImageLoaded
]
[]
Look at demo and code (you may need to change the random number in the image url to combat the browser caching the image).

Programatically disable Lazy Loading or infinite scroll with jQuery in Pinterest?

NOTE: New to this forum (UX/User Experience), so please let me know if this would be better in a different category. I searched Stack Exchange for "pinterest" and this forum seemed to have the most results. Thanks!
Hi guys. I'm writing a jQuery gist to grab links of all the images pinned to a given board in Pinterest. However, I've been running into the problem of having to repeatedly keep scrolling because all the results are not displayed on the same page. With the trendy "infinite scroll" or "lazy load" feature, one has to keep scrolling to the bottom without actually knowing if they are anywhere close because it seems to depend on your zoom percentage in your browser window and your window size as well, as to how many items display on your screen. I've been searching this for hours to no avail.
Searches I've already done keep returning non-productive results
The results I get when searching for
"Pinterest how to disable lazy loading" and "Pinterest how to disable infinite scroll"
keep returning the opposite of what I am looking for -- incorrect results for my purposes are anything like:
"How to add infinite scroll to my website",
"20 Useful Pinterest Tools",
or anything to do with adding infinite scroll.
The Problem: Infinite Scroll/Lazy Loading makes it hard for me to use browser plugins like jquerify (Chrome) and FireQuery (Firefox)
The issue for me is that I want to be able to view all my pins on a given board at once. Then I can use jQuery to manipulate all images on the page. Currently, infinite scroll makes it hard to keep track of where I'm at. I've tried stuff already by it's late at night and hard to remember everything. The important find was that in page source, Pinterest is using a "lazy" function. Here is what I found:
P.lazy = {
onImageLoad: function(a) {
var b = LOADED_CLASS;
P.overlap.isOverlappingViewport(a) && (b += FADE_CLASS);
a.className += b
}
};
This is just starting to be a deeper rabbit hole. I've checked for plugins to "remove", "disable", or "bypass" lazy loading, but haven't found any ... only those for adding it in.
Thanks in advance for your kind assistance and Cheers.
Pinterest loads cards via Ajax. When you scroll to the bottom of a page, browser javascript fires an Ajax call to load the next page full of cards.
This means it's not really possible to "disable" the infinite scrolling feature.
A few possible approaches:
Depending on how you're instantiating the browser, you might try setting or spoofing the window dimensions to a very large height. Pinterest may detect that height and attempt to load a window's worth of images, which may be enough to cover the feed you're trying to scrape.
If #1 is not practical for you, you can use javascript/jquery to keep scrolling the browser down until it has finished loading all the images. There are several ways to do this, since you are injecting javascript into the browser session.
(a) You can do this the "dumb" way with a loop that sets a timeout (setTimeout), then scrolls to the bottom (scrollTo()), then keeps going until the window stops scrolling and that comprises a kludgey auto-detect for the bottom of the page load.
(b) a more sophisticated approach would be to implement a listener for pinterest's ajax load function, (see the code, but it's a GET request to URL https://www.pinterest.com/resource/UserHomefeedResource/get/). An ajaxComplete() jQuery handler may help you detect the completion of a page load request so you can scrape the new images loaded.
Hope that helps

PHPUnit and WebDriver(Selenium2) - How to operate an element before the page's fully loaded?

By default , Webdriver always wait for a page's full loading, then find the element on this page and operate it.
e.g. open the google.com website, wait for its full loading, then find the search button ,and click it.
Sometimes, the page connects to some external link ,such as GA (statistics service), which usually takes too much time. And the button that I want to click has been loaded before the page's completely loaded.
How can I let Webdriver click a button when the button has been loaded ,when other parts of the page are still in loading progress?
You could always put a wait command in there.
sleep(5);
This will make it ' sleep for 5 seconds '
Though, it's easier to use ' waitForElementPresent();
$this->waitForElementPresent("YOURELEMENT","50000");
this will make your script wait for 50 seconds or until the element is loaded
YOURELEMENT = the locator
50000 = The timeout

How to add query string variables to pages in Windows8 app using html & JS

I'm building a navigation app for Windows 8 using Html & JS. For some of my div's, I am handling the onclick to do the following code, WinJS.Navigation.navigate("/pages/video/video.html"), which is a video page that simply plays a video. Before that code is called, I'm setting a hidden input element in default.html , <input id="currentVideoId" type="hidden" /> with the value of the video id that is clicked.
That way, on my video page, I can grab the current value of the hidden input to figure out which video to ajax load for the user.
Question: how can I instead navigate the user to /pages/video/video.html?id=555 ? I tried that, but my video.html did not seem to load at all. If I can do that, then in my video.js file I can look for the query string var to get the id of the video it should play.
Issue: if I don't do this, then if I go from 1 video to another video (I have an "Up next" control on each video page pointing to the next video in sequence), the back button doesn't work correctly as it just goes to the last video played.
You can use the same navigate function with the second parameter:
WinJS.Navigation.navigate("/pages/video/video.html", videoId);

Prioritize "Buy Now" Button Image

Today, while testing my website on a connection slower than my usual work connection, I noticed that the Chrome was downloading a bunch of other images on my product detail page before downloading the "Buy Now" button image. This is a problem because without the buy now button, there is no way to actually add the product to your shopping cart.
I'm looking for a way to force the browser to download the image for the button first, before any other images. Any ideas?
you could set your images to display:none then turn them back to inline with javascript after the page loads, starting with the paypal image...