爬取的数据带有换行符
从网上爬取的数据,里面带换行符,没法排版出去,求大佬解答下 发代码,不要只贴张图 zltzlt 发表于 2020-4-2 17:51发代码,不要只贴张图
import requests
import bs4
from bs4 import BeautifulSoup
r = requests.get('https://yanyu.huijiwiki.com/wiki/伙伴成长以及加点属性排行一览')
r.encoding = r.apparent_encoding
html = r.text
soup = BeautifulSoup(html,"html.parser")
table = soup.find('table').children
ulist = []
for tr in table:
if isinstance(tr,bs4.element.Tag):
td = tr('td')
if td ==[]:
continue
ulist.append(.string,td.string,td.string,td.string])
print(ulist)
这样可以吗:
import requests
import bs4
from bs4 import BeautifulSoup
r = requests.get('https://yanyu.huijiwiki.com/wiki/伙伴成长以及加点属性排行一览')
r.encoding = r.apparent_encoding
html = r.text
soup = BeautifulSoup(html, "html.parser")
table = soup.find('table').children
ulist = []
for tr in table:
if isinstance(tr, bs4.element.Tag):
td = tr('td')
if not td:
continue
ulist.append(.string, td.string, td.string, td.string])
print(*("".join(i) for i in ulist), sep="\n") zltzlt 发表于 2020-4-2 17:54
这样可以吗:
不行,还是就一列下来, import requests
import bs4
from bs4 import BeautifulSoup
r = requests.get('https://yanyu.huijiwiki.com/wiki/伙伴成长以及加点属性排行一览')
r.encoding = r.apparent_encoding
html = r.text
soup = BeautifulSoup(html, "html.parser")
table = soup.find('table').children
ulist = []
for tr in table:
if isinstance(tr, bs4.element.Tag):
td = tr('td')
if not td:
continue
ulist.append(.string, td.string, td.string, td.string])
print(*(" ".join(j[:-1] for j in i) for i in ulist), sep="\n") zltzlt 发表于 2020-4-2 17:58
谢大佬
页:
[1]