[Python] Precautions when retrieving data by scraping and putting it in the list

Precautions when scraping This is what to do when you get stuck in a swamp.

test.py


for s in name:
  name_list=[]
  name_list.append(s.string)

The problem with this code is the location of name_list. At this position, the contents of name_list will be updated every time. In other words, it is turned with for, but in the end only the last element of name Not append to name_list.

So let's change the position of name_list.

test.py


name_list=[]
for s in name:
  name_list.append(s.string)

By putting name_list out of for, the elements of name are acquired in order, The code will be append.

In particular, I first tried 1P, 1 element scraping, and then scraped the whole thing. Since we do it, we rarely use for in the testing stage.

Therefore, if you make a mistake in the position of the empty list when scraping the whole thing. It will be like this.

Recommended Posts

[Python] Precautions when retrieving data by scraping and putting it in the list
I checked the reference speed when using python list, dictionary, and set type in.
Differences in behavior between append () and "+ =" operators when adding data to a list in Python
Try scraping the data of COVID-19 in Tokyo with Python
[Python] It might be useful to list the data frames
Sort and output the elements in the list as elements and multiples in Python.
Scraping desired data from website by linking Python and Excel
Recursively get the Excel list in a specific folder with python and write it to Excel.
Difference between list () and [] in Python
Precautions when using pit in Python
Hashing data in R and Python
processing to use notMNIST data in Python (and tried to classify it)
Scraping the schedule of Hinatazaka46 and reflecting it in Google Calendar
Precautions when passing def to sorted and groupby functions in Python? ??
Scraping the list of Go To EAT member stores in Fukuoka prefecture and converting it to CSV
Scraping the list of Go To EAT member stores in Niigata prefecture and converting it to CSV
Precautions when pickling a function in python
[Python] Sweet Is it sweet? About suites and expressions in the official documentation
OR the List in Python (zip function)
Python data structure and internal implementation ~ List ~
Difference between append and + = in Python list
I set the environment variable with Docker and displayed it in Python
Read the file line by line in Python
Read the file line by line in Python
Easily graph data in shell and Python
Find it in the procession and edit it
Get the EDINET code list in Python
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
plot the coordinates of the processing (python) list and specify the number of times in draw ()
Make a Python program a daemon and run it automatically when the OS starts
[Python] How to name table data and output it in csv (to_csv method)
Divides the character string by the specified number of characters. In Ruby and Python.
Scraping the rainfall data of the Japan Meteorological Agency and displaying it on M5Stack
Note that I understand the least squares algorithm. And I wrote it in Python.
Fourier transform the wav file read by Python, reverse transform it, and write it again.
Get data via salesforce API (Bulk API) in Python and load it into BigQuery
Use python on Raspberry Pi 3 and turn on the LED when it gets dark!
Get the last element of the array by splitting the string in Python and PHP
Scraping the holojour and displaying it with CLI
[Python] Sort the list of pathlib.Path in natural sort
Python variables and data types learned in chemoinformatics
Receive and display HTML form data in Python
When I try matplotlib in Python, it says'cairo.Context'
[Python] Swapping rows and columns in Numpy data
Make a copy of the list in Python
About the difference between "==" and "is" in python
Precautions when dealing with control structures in Python 2.6
Precautions when installing packages in the conda environment
When the axis and label overlap in matplotlib
The story of reading HSPICE data in Python
Search by the value of the instance in the list
POST JSON in Python and receive it in PHP
List the AMIs used by AWS Data Pipeline
Sort tuple list in Python by specifying the ascending / descending order of multiple keys
[Python Data Frame] When the value is empty, fill it with the value of another column.
The result of making a map album of Italy honeymoon in Python and sharing it
[Selenium] Open the link in a new tab and move it [Python / Chrome Driver]
When I checked the query generated by Django, it was issued in large numbers
I compared the speed of the reference of the python in list and the reference of the dictionary comprehension made from the in list.
I want to replace the variables in the python template file and mass-produce it in another file.
[Python] Precautions when it does not work even if TimedRotatingFileHandler is set in basicConfig in python2