I have been trying to get my head around selenium to upload image in Facebook. As per this answer, I am able to do so using the following code:
driver.find_element_by_id("IdOfInputTypeFile").send_keys(os.getcwd()+"/image.png")
But, how can I add the caption to the very image on facebook?
Related
I am working on a Python project to scrap videos from Instagram using Selenium and request.
I am following the following link but it seems Instagram changed its settings:
https://www.youtube.com/watch?v=3DCtaJvf6VA&list=PLEsfXFp6DpzQjDBvhNy5YbaBx9j-ZsUe6&index=17&ab_channel=CodingEntrepreneurs
However, after I get a link of Instagram video, it's like this:
blob:https://www.instagram.com/4ddaf674-312a-4366-ad12-136bda7b6c8e
Hence, I cannot download the video. And I have looked at similar posts and they can find m3u8 or .ts in the Inspection. However, I cannot find any of them. Could anyone help?
I am looking to find all images in a website without having to click through every image. For example, the first page contains a bunch of images, click the first image and goes to another page with the story/images. Retrieve the image/text and so on.
Site of interest is: https://www.homestolove.com.au/australian-house-and-garden.
I have found that all image xpaths ends with /img, as per below. Is there away to do this using Selenium? Can I use regex to search the pages? Using Selenium because of JS content.
xpath
//*[#id="app"]/div/div/div[3]/div/div[1]/div[1]/section/div/div[1]/div[3]/article[3]/div/a/span/picture/img
Or do I need to click on every page, kinda painful.
How is this normally done?
Thanks.
As you said, you want to select the images, you can use
list_of_img = driver.find_elements_by_tag_name('img')
and then iterate through list_of_img.
So in your case,
from selenium import webdriver
driver = webdriver.Chrome('webdriver-meta\\chromedriver.exe')
driver.get("https://www.homestolove.com.au/australian-house-and-garden")
imgs = driver.find_elements_by_tag_name('img')
I want to use Selenium webdriver to download image from this site
each day there is a new page created, on this new page, images will be uploaded to it around 6 pm.
url = 'http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021'
driver.get(url)
images = driver.find_elements_by_tag_name('img')
for image in images:
print(image.get_attribute('src'))
when i run the code, even when no images are seen in regular browser (before 6pm), using selenium i still can get a list of those image urls,
# sample output from code
http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021/ukk-KlusterBaruHarian9.jpg
http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021/ukk-KlusterBaruHarian10.jpg
http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021/statskluster01.jpg
http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021/statskluster02.jpg
http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021/statskluster03.jpg
http://covid-19.moh.gov.my/terkini/2021/06/situasi-terkini-covid-19-di-malaysia-24062021/taburankes-all.jpg
the img url exist but the image seems to come up as 404 error.
I can even use wget on the img url to download, but the result is an empty/corrupted img
can someone explain to me these behaviours (I have no web development knowledge) and how to bypass it? I only want to download the image when only it is really there.
2 issues here:
the URL you are using is loading very slowly or even not loaded at all, this is why you getting the Error 404
You have to put wait / delay before performing images = driver.find_elements_by_tag_name('img') to let the page load completely.
UPD
if the error 404 appears after clicking a link on the web page it means that the link is broken or there is some other server side issue. It is not caused by wrong Selenium code. Just some problems with that web site.
So I have this code in Python3 that scraps data from websites through object recongnition (I used this to automate the download process inside a flash player based website) and Selenium. The problem is that I'm stuck with this website that have a custom made Captcha where the user have to select the different image from the group and I donĀ“t know how to download or get these images from the site in order to identify the different one, has anyone solved a problem like this? or have an idea on how to solve this captcha with any other technique or method?
This is the login that has the CAPTCHA
And here's the link to the site which is in spanish. The captcha basically says "Select the different image"
https://portalempresas.sb.cl/login.php
Thanks!
To download those images as png files you could do:
from io import BytesIO
from PIL import Image
# Download image function
def downloadImage(element,imgName):
img = element.screenshot_as_png
stream = BytesIO(img)
image = Image.open(stream).convert("RGB")
image.save(imgName)
# Find all the web elements of the captcha images
image_elements = driver.find_elements_by_xpath("*//div[contains(#class,'captcha-image')]")
# Output name for the images
image_base_name = "Imagen_[idx].png"
# Download each image
for i in range(len(image_elements)):
downloadImage(image_elements[i],image_base_name.replace("[idx]","%s"%i))
Edit 1:
If you want to compare 2 images to see if they are equal you could try with this post
Edit 2:
Using the solution edited above, these are the results:
I want to extract and display Youtube search results for a query to the user.
In that process, I have completed fetching the Youtube link and also extracted the title from the link.
Nevertheless I also want the thumbnail of that link displayed, same as that displayed in Youtube suggestions section.
For a question like this, I'd recommend using the site:youtube.com Google Images search, and just have a look at one or two thumbnails. I believe the below should work in all cases, though you'd need to test on different types of videos.
If the video URL is https://www.youtube.com/watch?v=xxxxxxxxxxxx
The thumbnail URL is https://i.ytimg.com/vi/xxxxxxxxxxxx/maxresdefault.jpg