Python Beginner: Passing Selenium WebElement Object to PHP

Nick Dawes

I'm interested in scrapping data from a website, and pass the data for use it in PHP. I have had a look around, and the best suggestion I have been able to find is to first serialise the Python data and then pass it along.

The issue I have is that I'm unsure how to serialise the Python data.

I'm using Selenium, and I have the following code.

test = browser.find_elements_by_css_selector("table#resultstable td")

I can see the data I want to use by running the variable through a loop and printing it.

for val in test:
    print(val.text)

However when I try to serialise the object, I receive the following error:

json.dumps(test)
....
TypeError: Object of type 'WebElement' is not JSON serializable!

I Hope somebody can point me in the right direction, I'm happy in PHP but I have only begun to look Python recently.

Foon

JSON the data format is limited in what it can store (numbers, strings, booleans, and then arrays or maps (what python calls dictionaries) of these elements (or other arrays or maps which at some point end in one of those formats). json the python library for manipulating json data can therefore only dump to a json string something that fits those rules. In your case, I'd suggest as a simple starting point:

columns = [val.text for val in test] # convert to a list of strings, where each string is the td.text

json.dumps(columns) should then give you something useful

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Python Selenium - Interact with the next WebElement object in a list

Selenium / Python TypeError: 'WebElement' object is not iterable

Object of type 'WebElement' has no len() - Python Selenium

Python and how to get text from Selenium element WebElement object?

Python Selenium - AttributeError : WebElement object has no attribute sendKeys in textarea

TypeError: 'WebElement' object is not subscriptable error submitting form using Selenium and Python

Python Selenium - Check if a WebElement is equal to another WebElement

how to import selenium WebElement in python

Selenium | How to iterate | TypeError: 'WebElement' object is not iterable

Selenium Object of Type WebElement has no len()

AttributeError: 'WebElement' object has no attribute 'username' at selenium?

Selenium Python AttributeError: 'WebElement' object has no attribute 'select_by_visible_text'

AttributeError: 'WebElement' object has no attribute 'Click' error trying to Click on a link using Selenium Python

How to get class name of the WebElement in Python Selenium?

Python Selenium WebElement element - invalid syntax

Make WebElement visible via Selenium with Python with JavaScript

Override .click() method of webElement in selenium using Python

How to retrieve the text of a WebElement using Selenium - Python

How to extract webelement with Selenium Webdriver in Python

Python NoneType object is not callable (beginner)

Python Passing Object to Object

Find subdivs within selenium in python ( selenium.webdriver.firefox.webelement)

AttributeError: 'WebElement' object has no attribute 'copy' error when moved the function Select to a common file using Selenium Python through Django

Selenium - Universal Way to Convert "WebElement" to Javascript or JQuery Object

Selenium 'WebElement' object has no attribute 'Get_Attribute'

Selenium Instagram Login: 'WebElement' object has no attribute 'send_Keys'

Getting TimeoutException when scraping an empty Webelement using Python Selenium

How to click on the webelement with in the highlighted script using Selenium and Python

Get the sibling element of a WebElement without XPath [Python/Selenium]