Python3 selenium can be utilized to extract the profile image link from a Facebook account

How can I fetch the Facebook profile image link using Python3 and Selenium?

Upon inspecting the profile photo element, the following information is obtained:

<image style="height: 168px; width: 168px;" x="0" y="0" height="100%" preserveAspectRatio="xMidYMid slice" width="100%" xlink:href="https://scontent.fskp2-1.fna.fbcdn.net/v/t1.0-1/p160x160/66377281_10219519738489211_3470999363818356736_n.jpg?_nc_cat=102&amp;_nc_ohc=wwARRHDG764AX8QTDeA&amp;_nc_ht=scontent.fskp2-1.fna&amp;_nc_tp=6&amp;oh=af9af2ffed61664c18229d3474cea541&amp;oe=5ECC34A6"></image>

Despite this, running $x('//image') returns 0 results. I am already logged into Facebook. Any suggestions on how to proceed?

Answer №1

This is the method I used to tackle this issue.

The solution involved capturing a screenshot of the entire screen using a browser automation tool like selenium, followed by cropping the image to specific coordinates.

# Using selenium for browser automation
from PIL import Image
...
driver.save_screenshot("shot.png")
x = 100
y = 80
w = 200
h = 220
width = x + w
height = y + h

im = Image.open('shot.png')
im = im.crop((int(x), int(y), int(width), int(height)))
im.save('image.png')

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtain some content using Java along with Selenium WebDriver

I only want to extract the text "Invitation sent to xxxxx". I do not need the content inside the button tag. <button class="action" data-ember-action="" data-ember-action-3995="3995"> Visualizar profile </button> This is how I am c ...

Perform a task X number of times every X hour using Python and Django

I am looking to create a program that can perform a task a specified number of times within a given time frame. For example, I want the task to be done 10 times every hour, or 10 times every day, or 3 times every day. I want this to be customizable by prov ...

When using Selenium webdriver, the function find_elements_by_X sometimes results in an empty list being

My objective is to compile a list of the names of all newly posted items on within a 24-hour period. After some research, I've discovered that Selenium is the ideal tool for this task as the website I am scraping is dynamic and loads more content as ...

Communicating between a Python Client and a nodeJS Server using Socket.IO

I am attempting to transmit data from my Raspberry Pi (using Python 2.7.9) to my NodeJS server with socket.io. My objective is to continuously send multiple values from my Pi through a websocket connection to my local Node Server, which will then display ...

Determine the character within a string by using a numerical column as the index

Seeking assistance as I am aware there is a small detail I am overlooking - I have managed to locate the index of the desired character within a string with the following code: df['letter_idx'] = df['string'].str.find(':')-1 ...

Transferring information between Flask and JS using AJAX for a Chrome extension

I'm experimenting with AJAX calls to establish communication between my Javascript frontend in a chrome extension and the Flask API where I intend to utilize my Machine Learning algorithms. content.js console.log("Let's get this application ...

De-duplicate values within multiple JSON lists using Python

Despite the abundance of questions regarding duplicates, I am struggling to find a suitable solution for my specific case. My JSON structure looks like this: { "test": [ { "name2": [ "Tik", "eev ...

Downloading files automatically from a webpage

Seeking a way to automatically download a file from a website, as the current manual process is cumbersome. Each time involves logging in, navigating to the file, and clicking download. If anyone has advice on automating this task using tools like MS DOS ...

Selenium WebDriver is struggling to locate an element using link text

I'm currently facing a challenge in selecting an element that contains an anchor within a paragraph inside a div. The HTML structure I am working with is as follows: <a class="item" ng-href="#/catalog/90d9650a36988e5d0136988f03ab000f/category/DATA ...

Guide to eliminating any negative numbers from a list using Python's lambda functions

After successfully implementing a lambda function to sort a list, I am now looking to remove all the negative objects from the list using lambda functions. dto_list.sort(key=lambda x: x.count, reverse=True) Is there anyone who knows how to write the lamb ...

The Pandas DataFrame is displaying cells as strings, but encountered an error when attempting to split the cells

I am encountering an issue with a Pandas DataFrame df. There is a column df['auc_all'] that contains tuples with two values (e.g. (0.54, 0.044)) Initially, when I check the type using: type(df['auc_all'][0]) >>> str However, ...

Steps for organizing directories in a CSV document

I need help with a script that lists directory names, file names, mp4 files, and empty directories in a CSV file. However, the output is being printed multiple times. Any assistance would be greatly appreciated. Thank you! import csv import os import sys ...

Tips on parsing JSON data from a URL in Python to generate a helpful dictionary

The data that I am working with can be accessed here - JSON Information Currently, this is the code I am using to read the data. However, the output appears to be unfamiliar, and I am struggling to figure out how to utilize it: import requests site=&apo ...

Finding the smallest value within the data from the past N days

In my dataset, I have the following information: ID Date X 123_Var 456_Var 789_Var A 16-07-19 3 777 250 810 A 17-07-19 9 637 121 529 A 20-07-19 2 295 272 490 A 21-07-19 3 778 600 ...

Pytorch issue: RuntimeError - The last dimension of the input must match the specified input size. Expected dimension 7, but received dimension 1

I am currently delving into the realm of machine learning and working on constructing an LSTM neural network. My model takes in 7 features as input and aims to predict 2 labels. However, I encountered an error when passing all 7 inputs into the LSTM laye ...

Reducing the number of features of a single image during the inference process

I am currently working on training a SVM classifier with scikit-learn. During the training process, I need to decrease the dimension of the feature vector. To achieve this, I have utilized PCA for dimensionality reduction. pp = PCA(n_components=400).fit(fe ...

Unable to input data into form text box using Selenium WebDriver

Hello, I have encountered an issue while using the way2sms website and trying to enter a mobile number in the send SMS screen with Selenium WebDriver. Here is the relevant HTML code: form id="smsFrm" name="smsFrm" method="post"> <input id="ssaction" ...

Tips for extracting a number from a div block with xPath

Recently, I started learning about xPath and encountered a challenging task. I need to extract the text "22 973 ₴" from this code snippet. Can anyone advise me on how to achieve this? <div class="col search_price discounted responsive_secondrow ...

Select the list item containing the desired text by clicking on it

When trying to click on a specific element based on the text displayed on this page using Python 3 and Chrome driver, I encountered an issue. For instance, when searching for "BEBES", I used the following code: WebDriverWait(browser, 10).until(EC.element_ ...

Divide the string at each second instance of an unidentified element

I have a string containing a series of coordinates that represent various polygons. Each polygon is closed, meaning it has the same starting and ending coordinates. My goal is to separate each polygon into its own string or list. '17.17165756225586 - ...