- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试运行这个以前有效的脚本:
import csv
from selenium import webdriver
from time import sleep
from parsel import Selector
from selenium.webdriver.common.keys import Keys
from collections import defaultdict
from selenium.webdriver.support.select import Select
####### reading from the input file ##########
columns = defaultdict(list) # each value in each column is appended to a list
# get the list of keywords from the csv file
with open('query.csv', 'r') as csvfile:
reader = csv.DictReader(csvfile) # read rows into a dictionary format
for row in reader: # read a row as {column1: value1, column2: value2,...}
for (k, v) in row.items(): # go over each column name and value
columns[k].append(v) # append the value into the appropriate list
# the list containing all of the keywords
search_query_list = columns['Keyword']
########## start scraping ###############
rb_results = []
# create a driver and let it open google chrome
driver = webdriver.Chrome("chromedriver")
# get linkedin website
driver.get('https://www.redbubble.com/')
sleep(0.5)
for i in range(len(search_query_list)):
next_query = search_query_list[i]
# get RB website
driver.get('https://www.redbubble.com/')
# get the search by its id
search_bar = driver.find_element_by_name("query")
sleep(0.5)
# enter the query to the search bar
search_bar.send_keys(next_query)
# press enter
search_bar.send_keys(Keys.RETURN)
sleep(1)
# from parsel's selector get the page source
sel1 = Selector(text=driver.page_source)
sleep(0.5)
# prima maglietta //
continue_link = driver.find_element_by_class_name('shared-components-ShopSearchSkeleton-ShopSearchSkeleton__composedComponentWrapper--1s_CI').click()
sleep(1)
sel2 = Selector(text=driver.page_source)
sleep(0.5)
################## get TAGS ###############
# Check tags for all products
try:
# get the tags for the search query
tags_rb = driver.find_element_by_class_name("shared-components-Tags-Tags__listContent--oLdDf").text
tags_rb = str(tags_rb)
# if number of products is found print it and search for the prime
# print the number of products found
if tags_rb == None:
rb_results.append("0")
else:
#rb_results = str(tags_rb)
rb_results.append(tags_rb)
except ValueError:
continue
#except:
#rb_results.append("errore")
###### writing part ########
with open ("rb_results.csv","w", newline='') as resultFile:
writer = csv.DictWriter(resultFile, fieldnames=["Rb Results"],delimiter='\t')
writer.writeheader()
writer.writerows({'Rb Results': item} for item in rb_results)
resultFile.close()
当我运行此脚本时,我遇到此错误:
Traceback (most recent call last): File "rb-spider.py", line 18, in for row in reader: # read a row as {column1: value1, column2: value2,...} File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/csv.py", line 111, in next self.fieldnames File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/csv.py", line 98, in fieldnames self._fieldnames = next(self.reader) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 3362: invalid continuation byte
我不明白为什么会出现这个错误。有什么想法吗?
最佳答案
尝试使用encoding
属性。
# get the list of keywords from the csv file
with open('query.csv', 'r', encoding='utf-8') as csvfile:
...
关于python - Unicode解码错误: 'utf-8' codec can't decode byte 0xd5 in position 3362: invalid continuation byte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421807/
我得到了一些有趣的结果,试图辨别使用 Encode::decode("utf8", $var) 之间的区别。和 utf8::decode($var) .我已经发现,在一个变量上多次调用前者最终会导致错
我尝试使用 FlushedInputStream :Android decoder->decode returned false for Bitmap download 但没有任何变化,因为我使用:B
我有一小部分代码: from pyasn1.type import univ from pyasn1.codec.ber import decoder decoder.decode(binary_fi
这个问题在这里已经有了答案: Instantiated optional variable shows as nil in Xcode debugger (2 个答案) 关闭 2 年前。 在 Swi
我在 Playground 中有以下示例代码。如果结果符合 Decodable 协议(protocol),我想解码网络请求的结果。 知道为什么这段代码不起作用吗? protocol APIReques
我正在尝试使用 imagecreatefromwebp() 将 webp 文件转换为 JPEG,但不幸的是,它向我发出警告:警告:imagecreatefromwebp():WebP 解码:无法解码输
我试图覆盖 JSONDecoder 解码数据的方式。 我尝试了以下方法: struct Response : Decodable { init(from decoder: Decoder) t
ACTIVATE_THIS = """ eJx1UsGOnDAMvecrIlYriDRlKvU20h5aaY+teuilGo1QALO4CwlKAjP8fe1QGGalRoLEefbzs+Mk Sb7
我正在尝试使用 swift 4 来解析本地 json 文件: { "success": true, "lastId": null, "hasMore": false,
我的代码有问题。 我正在尝试使用ExtJS和Codeigniter制作上传文件格式。 这是我的下面的代码, Ext.require([ 'Ext.form.field.File',
我有一些遗留代码正在调用 sun.net.www.ParseUtil.decode()。我想避免调用供应商特定的函数,所以我想用其他东西替换调用。 我可以使用 java.net.URLDecoder.
使用 Sonatype Nexus,我仅在访问 /nexus/#admin/support/status 时收到此错误消息. Ext.JSON.decode(): You're trying to d
我正在学习 Elm,让我感到困惑的一件事是“Json.Decode.succeed”。根据docs succeed : a -> Decoder a Ignore the JSON and produ
有什么区别 URLDecoder.decode(String s) 和 URLDecoder.decode(String s, String enc) 我有一个 cookie 值,例如 val=%22
使用 Google Apps 脚本,我想解码 HTML,例如: Some text & text ¢ 存储为: Some text & text ¢ 所以,类似的问题:How t
我正在对带有字幕的视频进行编码,但出现错误“解码的字幕文本中的 UTF-8 无效;可能缺少 -sub_charenc 选项。解码流时出错”,但视频还是编码了。忽略此错误的后果是什么?谷歌搜索显示一个人
我有如下代码: cn_bytes = [157, 188, 156] cn_str = "" clen = len(cn_bytes) count = int(clen / 3) for x in r
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
This script give you a decoded listing from an encoded file. Supports *,je, ,vbe, .asp, .hta, .htm,
telnet客户端响应如何解码 我认为这是一个特定的响应,因为所有思科服务器都有相同的响应.这段文字的名称是什么,我如何解密它 '\xff\xfb\x01\xff\xfb\x03\xff\xfd\x1
我是一名优秀的程序员,十分优秀!