I'm new to programming. Using selenium with Python 3.6.4,
I want to do web scraping. But in the page
Extract necessary elements specified by xpath and save them in CSV file
I'm going to look at the contents, but the following strings are lined up.
How can you preserve the contents of an element?
I would be happy if you could tell me.
The contents of the CSV file are as follows.
Applicable source code
"[<selenium.webdriver.remote.webelement.WebElement (session =" "0daf7b54557cdd8a62f84f4ef9eca9bd" ", element =" "0.5295562174369803-1" ")> ;,<selenium.webdriver.remote.webelement .WebElement (session = "" 0daf7b54557cdd8a62f84f4ef9eca9bd "", element = "" 0.5295562174369803-2 "")> ;,<selenium.webdriver.remote.webelement.WebElement (session = "" 0daf7b54557cdd8a62f84f4ef9eca9b0.5 "562 3 "")> ;,
from selenium import webdriver import csv import time CHROME_PATH = "xxxxxxxxxxxx" TARGET_URL = "https: // xxxxxxxxxxxx /" driver = webdriver.Chrome (CHROME_PATH) driver.get (TARGET_URL) driver.find_element_by_class_name ("searchInput"). send_keys ("xxxxxxxxxxxx") #Enter a specific keyword in the site search window driver.find_element_by_class_name ("searchButton"). click () #Click the search button driver.find_element_by_xpath ('// a [contains (text (), "article")]'). click () #Click on the link containing the string "article" csvw = csv.writer (open ("output.csv", "w", encoding = "utf-8", newline = "\ n"), delimiter = "\ t") # Prepare CSV file csvlist =  #Prepare a list to store necessary elements for i in range (10): comp = driver.find_elements_by_xpath ('// div [@ class = "xxxxxxx"]') Specify the location to be extracted from the HTML file with #xpath and store it in the variable csvlist.append (comp) #Store extracted elements in a list prepared in advance csvw.writerow (csvlist) #Write elements stored in list to CSV file
Answer # 1
If you want to get the innerText of
div, you need comp.text.
If you can help.
- python - createtoolhelp32 cannot get the values of various registers with snapshot ()
- python - cannot get ticker information of oanda api
- python - cannot drop files or texts on ttk widget with tkinterdnd2
- python 3x - matplotlib cannot be imported
- python - error that cannot reshape
- python - i want to limit the number of images to be extracted
- python - importerror: cannot import name'config_context'
- python - when training data is read, the file name becomes ds_store and it cannot be found
- python - i cannot install pyav
- python - css cannot be read when debug=false in the environment built with django+https-portal in the docker environment do not
- python - cudaget_device(gpu_device)use() cannot be executed
- python 3x - i cannot understand the error message displayed by the jupyter notebook in the process of face recognition using dee
- python 3x - cannot display png file
- python - i'm getting an error that render_to_response cannot be imported by django
- python - cannot execute selenium on web (cgi)
- python 3x - regarding the fact that the seaborn graph cannot be drawn properly
- python 3x - python, selenium, radio button cannot be selected
- python - cannot move files to /opt
- double quotes cannot be escaped in python's append method
- python 3x - cannot install python package with atom
- i can't successfully store the data scraped by selenium using python in the list
- i want to process requests asynchronously with python 3 and throw more and more requests
- web scraping in python:error in send_keys
- i don't know how to specify selector in scraping in python
- datetime - i want to use python, seleniumu to enter the date in the hp text box
- python 3x - displaying ie11 with selenium causes the program to stop halfway
- python 3x - ie display does not work with selenium
- python 3x - get element of selenium popup
- python 3x - cannot specify element with selenium
- python 3x - nosuchelementexception exception occurs when trying to get by id with python selenium