我试图用scrapy蜘蛛剥离\ r \n\t字符,然后制作一个json文件.
我有一个"描述"对象,它充满了新的行,并没有做我想要的:将每个描述与标题相匹配.
我尝试使用map(unicode.strip()),但它并没有真正起作用.作为scrapy的新手我不知道是否有另一种更简单的方法或者map unicode是如何工作的.
这是我的代码:
def parse(self, response):
for sel in response.xpath('//div[@class="d-grid-main"]'):
item = xItem()
item['TITLE'] = sel.xpath('xpath').extract()
item['DESCRIPTION'] = map(unicode.strip, sel.xpath('//p[@class="class-name"]/text()').extract())
Run Code Online (Sandbox Code Playgroud)
我也尝试过:
item['DESCRIPTION'] = str(sel.xpath('//p[@class="class-name"]/text()').extract()).strip()
Run Code Online (Sandbox Code Playgroud)
但它引发了一个错误.什么是最好的方式?
我正在尝试使用 youtube-dl 从 youtube 中的播放列表列表中获取一些信息。我已经编写了这段代码,但它需要的不是视频信息而是播放列表信息(例如播放列表标题而不是播放列表中的视频标题)。我不明白为什么。
input_file = open("url")
for video in input_file:
print(video)
ydl_opts = {
'ignoreerrors': True
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(video, download=False)
for i in info_dict:
video_thumbnail = info_dict.get("thumbnail"),
video_id = info_dict.get("id"),
video_title = info_dict.get("title"),
video_description = info_dict.get("description"),
video_duration = info_dict.get("duration")
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
我正在尝试使用 lxml 解析本地 HTML,但出现错误,但我不知道为什么(对于错误的代码提前抱歉,我是新手)。
from lxml import etree, html
from StringIO import StringIO
parser = etree.HTMLParser()
doc = etree.parse(StringIO("test1.html"), parser)
tree = html.fromstring(doc)
CCE = tree.xpath('//div[@data-reactid]/div[@class="browse-summary"]/h1')
URL = tree.xpath('//a[@class="rc-OfferingCard"]/@href')
print 'CCE:', CCE
print 'URL:', URL
Run Code Online (Sandbox Code Playgroud)
这是错误:
File "test.py", line 8, in <module>
tree = html.fromstring(doc)
File "/usr/lib/python2.7/dist-packages/lxml/html/__init__.py", line 703, in fromstring
is_full_html = _looks_like_full_html_unicode(html)
TypeError: expected string or buffer
Run Code Online (Sandbox Code Playgroud) 我有一个巨大的文件,主要由书籍元数据(作者、标题、日期、网址)组成。我的问题是,我想对作者姓名(经常重复:一个作者可以有数百条记录)进行操作,并且我想对这些作者中拥有超过 X 条记录的子集进行操作。
例如,我有 200 条与“William Shakespeare”相关的记录,但只有一条 1 记录“John Black”等。重点是,作为一个经典的幂律,我有数十万个作者,其中大多数为 1 -2条记录。
使用“文本方面”>“计数”是不可能的,因为我的计算机死机了。
是否有一个查询仅根据某些记录的计数来获取其文本方面?
python ×2
clusterize ×1
lxml ×1
openrefine ×1
python-3.x ×1
scrapy ×1
unicode ×1
youtube ×1
youtube-dl ×1