抓取页面时如何删除\r\n? [英] How to remove \r\n when scraping a page?
本文介绍了抓取页面时如何删除\r\n?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过抓取页面创建了一个函数并运行,但输出给出了 \r\n
.我使用 strip
函数删除 \r\n
但它不起作用.为什么以及如何删除 \r\n
?这是链接:https://ibb.co/VtVV2fb
I have made a function by scraping a page and I run but the output gives \r\n
. I used strip
function to remove \r\n
but its not working. Why and how to remove \r\n
?
Here is the link: https://ibb.co/VtVV2fb
import scrapy
from .. items import FetchingItem
class SiteFetching(scrapy.Spider):
name = 'Site'
start_urls = ['https://www.rev.com/freelancers']
transcription_page = 'https://www.rev.com/freelancers/transcription'
def parse(self, response):
items = {
'Heading': response.css('#sign-up::text').extract(),
'Earn_steps': response.css('.pb2 .lh-copy::text , .mb1::text , .mb3 .lh-copy::text').extract(),
}
yield response.follow(self.transcription_page, self.trans_faqs, meta={'items':items})
def trans_faqs(self, response):
items = response.meta['items']
names = {
'name1': 'FAQ1',
'name2': 'FAQ2',
}
finder = {
'find1': '#whatentailed p::text , #whatentailed .mr3::text',
'find2': '#requirements p::text , #requirements .mr3::text'
}
for name, find in zip(names.values(), finder.values()):
items[name] = list(map(str.strip,response.css(find).extract()))
yield items
推荐答案
每当我有一个带有制表符或换行符的字符串时,我发现用 '' 替换它们对我很有效.
Whenever I have a string with tabs or newlines, I found that replacing them with '' works for me.
例如,如果你的字符串变量中有 \t 和 \n,你可以这样做:
For example, if you have both \t and \n in your string variable, you could do this:
string_variable.replace('\n','').replace('\t','')
到目前为止效果很好.
这篇关于抓取页面时如何删除\r\n?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文