【发布时间】:2020-11-07 12:38:47
【问题描述】:
我有一个在 pinterest 上执行任务的代码,它是手动工作的,必须在“pin_id =”区域填写一个数字,当我运行时,将完成重新固定,但是,我想:
- 从单列 csv 文件中填写“pin_id”区域中的数据。
- 每个任务之间有一些延迟(5-10 秒)。
- 能够限制每次运行的行数, 例如50,CSV文件可能有数百个数据,我不想一次运行所有数据。
[edited] 代码已编辑,我试过的最新的, 代码如下:
import json
import random
import time
import os
from csv import reader
import csv
import pandas as pd
from py3pin.Pinterest import Pinterest
pinterest = Pinterest(email='xxxx',
password='xxxx',
username='xxxx',
cred_root='cred_root')
def repin(pin_id='', board_id=myboard Id, section_id=None):
return pinterest.repin(board_id=board_id, pin_id=pin_id,
section_id=section_id)
with open('pin-test.csv','r') as csvfile: # use with to auto-close file
for row in csvfile.readlines(): # pin_id
repin(row) # board_id and section can use defaults
time.sleep(random.randint(1,3)) # wait 1-3 seconds
目前还没有限制要运行的行数的功能,
无论如何,编辑后的脚本也不起作用,
我在运行时得到这些:
C:\Users\Dav111\Desktop\Python\py3-pinterest-master>z-repin-test.py
Traceback (most recent call last):
File "C:\Users\Dav111\Desktop\Python\py3-pinterest-master\z-repin-test.py",
line 40, in <module>
repin(row) # board_id and section can use defaults
File "C:\Users\Dav111\Desktop\Python\py3-pinterest-master\z-repin-test.py",
line 35, in repin
return pinterest.repin(board_id=board_id, pin_id=pin_id,
section_id=section_id)
File "C:\Users\Dav111\Desktop\Python\py3-pinterest-
master\py3pin\Pinterest.py", line 433, in repin
return self.post(url=REPIN_RESOURCE_CREATE, data=data)
File "C:\Users\Dav111\Desktop\Python\py3-pinterest-
master\py3pin\Pinterest.py",
line 111, in post
return self.request('POST', url=url, data=data, files=files,
extra_headers=headers)
File "C:\Users\Dav111\Desktop\Python\py3-pinterest-
master\py3pin\Pinterest.py", line 103, in request
response.raise_for_status()
File "C:\python\Python38\lib\site-packages\requests\models.py", line 941, in
raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url:
https://www.pinterest.com/resource/RepinResource/create/
感谢您对此的帮助。
【问题讨论】:
-
我没有关注。也许样本数据和预期结果会澄清。我今晚去看看。
-
感谢回复,我把pin number放在"pin_id="前面,board number放在"board_id="前面,运行的时候会repin到我的board,但是我要填pin_id= 带有 CSV 文件中的数字,(一行),板号是恒定的,我不需要更改它,因此 CSV 文件只有一列,每行一个数字 106327241191390329、10766486599666429、10836855341311643,读取CSV 文件代码,只是我在网上找到的一个示例,我尝试使其与我拥有的代码一起使用。
-
如何在读取 csv 文件时出现 http 错误? :)