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