Troubleshooting problems with encoding in Python Selenium's get_attribute method

Currently, I am utilizing Selenium with Python to crawl the drop-down menu of this particular page. By employing the find_elements_by_css_selector function, I have successfully obtained all the data from the second drop-down menu.

However, when attempting to print both the group number and its corresponding model name using model.get.attribute('href'), I encountered an issue where the Korean characters in the model name appeared broken as shown below: 5%EC%8B%9C%EB%A6%AC%EC%A6%88 (which represents 5-series in BMW).

While I understand that 'model.text' provides only the model name, my requirement also includes retrieving the group name for each model simultaneously.

This necessitated me to use model.get.attribute('href') instead of model.text.

I would appreciate any assistance to help resolve this matter.

Below you will find a snippet of my code:

enter code here#!/usr/bin/env python
#-*- coding: utf-8 -*-

import re

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select

from bs4 import BeautifulSoup
from time import sleep

link = 'http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I'
driver = webdriver.PhantomJS()
driver.set_window_size(1920, 1080)
driver.get(link)
sleep(.75)

s = BeautifulSoup(driver.page_source, "html.parser", from_encoding='utf-8')

makers = ['아우디', 'BMW', '벤츠']

for maker in makers:
    # open manufacturer layer
    next_elem = driver.find_element_by_xpath('//a[@title="제조사 선택"]')
    next_elem.click()

    next_elem = driver.find_element_by_link_text(maker)
    print(maker)
    next_elem.click()
    print("clicked maker")
    sleep(.75)

    # open model layer
    next_elem = driver.find_element_by_xpath('//a[@title="모델 선택"]')
    next_elem.click()

    # select model

    models = driver.find_elements_by_css_selector("#layer_group ul.list li a")
    for model in models:
        print (model.get_attribute('href'))

Answer №1

The title in question does not have an href attribute. You can try the following code to list the option values (if any):

 elem = driver.find_element_by_xpath("//select[@title='모델 선택']").
 for option in elem.find_elements_by_tag_name('option'):
     print option.text

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

CSS: border-radius // background-color: white; rounded corners

Having recently delved into the world of HTML/CSS, I am currently working on a fun project to enhance my web development skills. In this project, I have created a search bar and successfully added round corners with border-radius. However, an issue arises ...

Understanding PyQt Documentation

After installing PyQt GPL v4.6.2 for Python v3.1 and Qt by Nokia v4.6.0 (OpenSource), I noticed that the documentation in PyQt is not displaying properly. Even the example docs are blank. I am seeking a step-by-step guide from someone on how to access the ...

A guide to verifying the data type of a CLI argument in Python's Click module

Currently, I am working on a click command that can accept arguments of both integer (int) and string (str) types. The challenge I'm facing is determining the type of argument passed within the function. Below is an example: import click @click.comm ...

Improper headings can prevent Chrome from continuously playing HTML5 audio

Recently, I encountered a peculiar and unlikely issue. I created a custom python server using SimpleHTTPServer, where I had to set my own headers. This server was used to serve .wav files, but I faced an unusual problem. While the files would play in an ...

Looking to adjust the positioning of text being inserted into a column - unable to utilize text-align or float properties

I'm struggling to position my text in a specific area within a column using CSS. Our app displays a price when a quantity is selected, but I can't seem to center the $14 under 'Item Total'. Even using float: center; hasn't worked f ...

Utilizing the text field feature within Twitter Bootstrap 3.0 in-line styling

I am attempting to create a horizontal form with an inline text field split into two sections: one on the left and one on the right. The left side will contain horizontal text fields, some of which are inline, while the right side will have a mix of inline ...

Craving assistance in coding permutations

Thank you for responding. I want to express my gratitude for your efforts in trying to assist me. Unfortunately, I have posted this problem on multiple websites and no one has been willing to help. Regarding my code, my objective is to count permutations. ...

What is the best way to add a button over an image using Tailwind CSS in Next.js?

I've been trying to display a button on top of an image using Tailwind CSS and Next.js, but I'm having trouble getting it to align properly. Here is the code snippet I've been working with: <div> <Image src={projectAiWrite ...

Positioning Google Chart in HTML

I'm attempting to arrange three distinct Google pie charts in a horizontal layout. At present, I have applied inline CSS for formatting purposes. Oddly enough, the third chart always ends up on a separate line. Could anyone kindly point out my error? ...

Move spaces from one string to another in Python

Is it feasible in Python 2 to replicate whitespace elements such as spaces and tabs from one string to another? For instance, if the original string includes three leading spaces and a trailing tab like " Hi\t", can those exact whitespace characters ...

Tips for creating a scrolling iFrame that moves with the background

I have recently created a website with a unique design feature. The background image acts as a border surrounding the main content, which is located within an iFrame. However, I've encountered an issue where scrolling the iFrame does not affect the ba ...

Once the form has been submitted, proceed to open a new page following processing

Trying to remove an entry or offer from the database and then return to the page with all entries/offers. Attempted using Javascript, but it successfully deletes the item without redirecting to the overview page. Is this the correct approach with Javascri ...

How can Pydantic be used to generate models in a recursive manner?

I am currently working with Pydantic and trying to implement it in the following way: from pydantic import BaseModel class Person(BaseModel): name: str age: int class Employee(BaseModel): person: Person data = { 'name': 'John Doe ...

a dynamic framework that fills out several forms

I am in search of a way to streamline the data entry process for my awards database. Currently, my "people" table consists of five fields: peopleid first middle last display For example, an entry could look like this: peopleid 120 first William middl ...

Error message: Unable to see Selenium command - Launch Browser - Robot Framework Ride

My computer is equipped with Selenium version 3.141.0 along with Python 3.7 Upon importing the library to Ride for a new Suite named WebAutomation, I encountered an issue where the OPEN BROWSER keyword does not appear in the test case (OpenBrowser): http ...

Error 404 - CSS file missing: encountering a 404 error while attempting to execute Flask code

Hello there! I'm still getting the hang of programming, especially when it comes to web development. Recently, I encountered an issue with my CSS file - whenever I link it to my HTML and run the Python code, I get an error saying that the CSS file can ...

Having Trouble Loading PHP File with Jquery

I've been struggling with using JQuery/Ajax to load the content of my PHP file into a div tag. Below is the code snippet from my page that attempts to load the file: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/ ...

Tips on sending a successful HTTP 200 response for a Slack API event request in Python using the request module

I am trying to handle an event request by sending back an HTTP 2xx response using the Request method in Python. Can someone please provide guidance on how I can achieve this smoothly? The current issue I am facing is that I have tunnelling software runnin ...

Having trouble extracting HTML output from a Selenium page when executing wdio.conf.js using the Selenium standalone service and Chrome browser

Upon running tests from wdio using the command 'wdio wdio.conf.js', an Error followed by html code of selenium page is being encountered. The package.json file contains the following configuration: { "name": "OpenWeathermap", "version": "1. ...

Obtaining the value of a particular cell and filling in any missing data in a PySpark dataframe

I am currently in the process of transforming a python code into pyspark. My goal is to utilize fillna to replace any missing values with a value from another column within the same dataframe, specifically at index 0. Here is the original python code that ...