dataabc / weiboSpider

新浪微博爬虫,用python爬取新浪微博数据
8.37k stars 1.98k forks source link

Cookie版爬取的微博id仅有bid一种格式,没有mid #236

Closed codingcindy closed 3 years ago

codingcindy commented 4 years ago
def bid2mid(bid):
    """convert string bid to string mid"""
    alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    base = len(alphabet)
    bidlen = len(bid)
    head = bidlen % 4
    digit = int((bidlen-head)/4)
    dlist = [bid[0:head]]
    for d in range(1,digit+1):
        dlist.append(bid[head:head+d*4])
        head += 4
    mid = ''
    for d in dlist:
        num = 0
        idx = 0
        strlen = len(d)
        for char in d:
            power = (strlen - (idx + 1))
            num += alphabet.index(char) * (base ** power)
            idx += 1
            strnum = str(num)
            while (len(d) == 4 and len(strnum) < 7):
                strnum = '0' + strnum
        mid += strnum
    return mid
dataabc commented 4 years ago

感谢建议。

上面的代码是可行的。才知道mid是可以通过bid得到,这样它们就是冗余的,二者使用其一就可以了,免cookie版中就出现了冗余字段。 在考虑要不要在本项目中加上mid字段,因为mid是免cookie版中的id,是有意义的,但是也是冗余的,可以由bid推出,所以比较纠结要不要添加。

非常有意义的代码,如果方便,能否提交一个pull request,具体就是修改https://github.com/dataabc/weiboSpider/blob/master/weibo_spider/parser/util.py,加上上面的函数就可以。这样你就成了本项目的Contributor。这不是强制的,因为代码是你的劳动成果,虽然不确定是否在结果中添加mid字段,但也能为有需要的人提供借鉴。不管如何,都非常感谢。

codingcindy commented 4 years ago

谢谢回复!已经提交了pull request。

我觉得最好还是保留这两种区分。一旦微博改变了bid-mid对应关系,仅用这个函数就无法找回丢掉的信息了。

dataabc commented 4 years ago

感谢pull request。

目前打算把mid作为隐藏属性,因为它和bid都是用来唯一标志微博的,bid就够了。将来如果有其它相关需求,再把mid作为输出字段。

pull request的代码没有问题,只是我发现git上有一点问题。现在的代码能够merge,但如果现在这样,你成不了Contributor,因为你github账号的email和git设置的email可能不同。因为在pull request页,commit(add function: bid2mid)旁的头像是和你的头像不一致的,所以猜测是email不同的原因。以前出现过明明merge了代码,但贡献人却没有成为Contributor的情况,原因好像就是email。如果github和git的email一样,头像也应该一样。

网上的解决办法有两种,不知道是否有效: 1.把git中设置的email添加到github账户中; 2.把git的email设置成github中的email,然后重新pull request。

基于以上原因,我暂时不merge代码,等待email配置好后再merge。这不是强制的,只是作为提醒我才说了这些,不修改也可以,我已经很感激了。如果您不想修改email,那我明天之前就merge。

再次感谢贡献代码

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

Closing as stale, please reopen if you'd like to work on this further.