小编Ete*_*ine的帖子

写入csv文件时,writerow因UnicodeEncodeError失败

我有这条线:

c.writerow(new_values)
Run Code Online (Sandbox Code Playgroud)

这会将许多值写入csv文件.通常它工作正常但有时会抛出异常并且不会在csv文件中写入该行.我不知道我怎么能找出原因.

这是我现在的异常处理:

        try:
            c.writerow(new_values)
        except:
            print()
            print ("Write Error: ", new_values)
Run Code Online (Sandbox Code Playgroud)

我评论了我自己的例外,它说:

    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u03b1' in position 14: character maps to <undefined>
Run Code Online (Sandbox Code Playgroud)

python csv exception-handling exception

11
推荐指数
2
解决办法
9152
查看次数

如何使用python从csv文件中仅读取特定范围的行?

例如,如何才能仅从该csv文件中的行5000到6000读取?此时,“用于阅读器中的行:”当然会遍历所有行。

所以我有这样的话:

with open('A.csv', 'rt') as f:
     reader = csv.reader(f, delimiter=';')
     for row in reader:
           response = urllib2.urlopen(row[12])
Run Code Online (Sandbox Code Playgroud)

此代码用于打开特定的URL链接。

python csv python-3.x

5
推荐指数
1
解决办法
4414
查看次数

Python与Selenium"元素未附加到页面文档"

我有一个python函数,应该点击产品的所有选项:

submit_button = driver.find_element_by_id('quantityactionbox')

elementList = submit_button.find_elements_by_tag_name("option")

for x in elementList:
    x.click()
Run Code Online (Sandbox Code Playgroud)

点击2个元素后,我收到此错误:

selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
Run Code Online (Sandbox Code Playgroud)

你能否告诉我为什么这个错误应用以及我能做些什么来成功通过所有元素?

python selenium

2
推荐指数
2
解决办法
9699
查看次数