I want to remove the extra \ r \ n from the list of articles I got by scraping, but I get the following error:
AttributeError:'list' object has no attribute'replace'
GoogleCrome 86.0.4240.75 (64bit)
Write a program in a Jupyter Lab notebook
The article in question looks like this.
#!/usr/bin/env python #coding: utf-8 from bs4 import BeautifulSoup import urllib.request as req import pandas as pd import numpy as num import re url = "https://www.msn.com/ja-jp" response = req.urlopen (url) soup = BeautifulSoup (response,'html.parser') lists = soup.find_all (href = re.compile ("/ ja-jp/news")) #Path is displayed at the bottom right of the site lists [1:21] select =  url_select =  for list in lists: select.append (list.string) url_select.append (list.attrs ['href']) selected = select.replace ('\ r \ n','') selected
select.strip ()Or try
select.re (r'(. +) \ R \ n')I tried, but all the errors were as above.
Does that mean that the specified object has no attributes to make sense of the error? Even so, I don't know how to deal with it.
I would appreciate it if you could let me know what you think.
Answer # 1
listIs a built-in function, so it has a different name
lstLet's use something like that.
When I actually move it,
lst.stringYou can get some things that are None, so after removing them
replace replaceWhat you did
appendI think it's okay.
for lst in lists: if lst.string: select.append (lst.string.replace ('\ r \ n','')) url_select.append (lst.attrs ['href'])
Answer # 2
selectIs a list, not a string
replace replacecan not.
For strings that are elements of the list
replace replacelet's do it.
list.stringFor (this is a string)
replace replaceI think I should do it.
- cannot post html form on local web server using python
- python 3x - cannot specify display position even using python3 tkinter geometry
- python - image cannot be read with cv2imread
- python - the file cannot be read
- in windows 10, temporary files are huge but cannot be deleted
- python - cannot be read by pdread_pickle
- cannot switch the python version with pyenv
- python - cannot get check box judgment
- python - the number typed in input cannot be calculated in datetime
- [python] pip cannot be used suddenly
- python - anaconda prompt cannot run file
- python - import cannot be executed after executing pip install construct
- [python] cannot get spreadsheet values
- python - what to do when you cannot read csv using pandas
- python - cannot specify unicode string of latin é character
- about dealing with parts that cannot be extracted during python3 scraping
- python - keras cannot be imported
- python - i cannot start tensorboard (i get an error, i was able to do it before)
- python - tensorflow cannot be imported
- python seleniun error modulenotfounderror: no module named'selenium'
- python - unable to extract img and alt contents from html
- python - web scraping what to do if you can only get one copy of data on starbucks hp
- python - the bet365 site cannot be scraped with selenium if you are familiar with it, could you please tell me?
- i want to use python kivy to run a program that works asynchronously
- python - is it possible to specify multiple condition elements with the find method?
- [python] if a browser alert dialog appears during scraping, press ok to continue processing [web scraping]
- python - i don't know the path of the button i want to scrape on the browser
- how to know when there is no information element in python scraping