마이리스트 종료 :파이썬 : 목록에 n을 r에 의 t을 대체하는 시작 n n을 제외하고 n을의 r n 의 t으로
['\n\r\n\tThis article is about sweet bananas. For the genus to which banana plants belong, see Musa (genus).\n\r\n\tFor starchier bananas used in cooking, see Cooking banana. For other uses, see Banana (disambiguation)\n\r\n\tMusa species are native to tropical Indomalaya and Australia, and are likely to have been first domesticated in Papua New Guinea.\n\r\n\tThey are grown in 135 countries.\n\n\n\r\n\tWorldwide, there is no sharp distinction between "bananas" and "plantains".\n\nDescription\n\r\n\tThe banana plant is the largest herbaceous flowering plant.\n\r\n\tAll the above-ground parts of a banana plant grow from a structure usually called a "corm".\n\nEtymology\n\r\n\tThe word banana is thought to be of West African origin, possibly from the Wolof word banaana, and passed into English via Spanish or Portuguese.\n']
예 코드 :
import requests
from bs4 import BeautifulSoup
import re
re=requests.get('http://www.abcde.com/banana')
soup=BeautifulSoup(re.text.encode('utf-8'), "html.parser")
title_tag = soup.select_one('.page_article_title')
print(title_tag.text)
list=[]
for tag in soup.select('.page_article_content'):
list.append(tag.text)
#list=([c.replace('\n', '') for c in list])
#list=([c.replace('\r', '') for c in list])
#list=([c.replace('\t', '') for c in list])
print(list)
웹 페이지를 긁어 낸 후에 데이터 정리를해야합니다. "\r"
, "\n"
, "\t"
을 모두 ""
으로 바꾸고 싶지만이 경우 자막이 있습니다. 자막과 문장이 혼합되어 있습니다 ().
모든 자막은 항상 \n\n
으로 시작하고 \n\r\n\t
으로 끝납니다. \aEtymology\a
과 같이이 목록에서 구분할 수있는 작업이 가능할 수 있습니다. \n\n
및 \n\r\n\t
을 \a
으로 따로 대체하는 경우 다른 부분의 요소가 \n\n\r
일 때 첫 번째 원인은 \a\r
이됩니다. 미리 감사드립니다!
이것은 아주 청초합니다! 그리고 쉽게 배우고 이해할 수 있습니다. 그냥 질문 목록 = [목록에 r에 대한 r.replace ('', x, 1)], 1은 무엇을 사용합니까? 내가 그것을 제거했을 때, 그것은 같은 결과를 출력했다.그냥 호기심 :) 감사합니다! –
Makiyo
@Makiyo 1은의 첫 번째 발생만을 대체합니다. 1을 제거하면 자막이 출력물에서 동일하게됩니다. –