Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问怎么保存视频页面链接 #587

Closed
SingleRottenChips opened this issue May 23, 2024 · 5 comments
Closed

请问怎么保存视频页面链接 #587

SingleRottenChips opened this issue May 23, 2024 · 5 comments

Comments

@SingleRottenChips
Copy link

纯python小白,自己试着作了以下更改:

1: 仿照"""获取微博视频url""",在 page_parser.py 增加"""获取微博视频页面的链接""":

   def get_video_page_url(self, info):
    """获取微博视频页面的链接"""
    video_page_url = u'无'

    weibo_id = info.xpath('@id')[0][2:]
    try:
        video_page_url = ''
        a_text = info.xpath('./div[1]//a/text()')
        if u'全文' in a_text:
            video_page_url = CommentParser(self.cookie,
                                           weibo_id).get_video_page_url()
        else:
            # 来自微博视频号的格式与普通格式不一致,不加 span 层级
            a_list = info.xpath('./div[1]//a')
            for a in a_list:
                if 'm.weibo.cn/s/video/show?object_id=' in a.xpath(
                        '@href')[0]:
                    video_page_url = a.xpath('@href')[0]
                    break
    except Exception as e:
        logger.exception(e)

    return video_page_url 
  1. csv_writer.py 的 self.result_headers 中加入:

('视频页面url', 'video_page_url'),

  1. weibo.py 的 def init(self) 中 加入:

self.video_page_url = ''

但生成的csv文件中,“视频页面url”一列是空白的。

请问有哪一步出错了吗?还是我还需要更改哪里?

@dataabc
Copy link
Owner

dataabc commented May 24, 2024

需要在page_parser.py修改get_one_weibo方法,你好像只是实现了有获取能力的方法,但是没有使用,需要在get_one_weibo中使用这个方法。

@SingleRottenChips
Copy link
Author

需要在page_parser.py修改get_one_weibo方法,你好像只是实现了有获取能力的方法,但是没有使用,需要在get_one_weibo中使用这个方法。

感谢回复🙏 现在可以写入获取到的链接了,但是没有链接时写入的是空白,而不是“无”。

请问还需要改哪里吗?

@SingleRottenChips
Copy link
Author

需要在page_parser.py修改get_one_weibo方法,你好像只是实现了有获取能力的方法,但是没有使用,需要在get_one_weibo中使用这个方法。

感谢回复🙏 现在可以写入获取到的链接了,但是没有链接时写入的是空白,而不是“无”。

请问还需要改哪里吗?

听从了Chatgpt的建议,在 def get_video_page_url(self, info) 中 添加:

    if video_page_url == '':
        video_page_url = u'无'

现在可以写入 无 了。

一开始想不明白为什么 get_video_page_url(self, info) 需要再赋值,刚才突然想到,如果链接不存在的话,

        video_page_url = CommentParser(self.cookie,
                                       weibo_id).get_video_page_url()

这里生成应该是空白,所以就写入空白?

考虑到视频原url过期后就打不开了,而视频页面url,只要微博未删除,即便设置了“仅半年可见”,也是可以通过自己发布 正文为页面url 的微博 来看到视频的;要不要考虑一下把原本写入视频url改为视频页面url呢?

@dataabc
Copy link
Owner

dataabc commented May 24, 2024

暂时没有这个打算。

@SingleRottenChips
Copy link
Author

暂时没有这个打算。

好吧。感谢大神的开发和指导❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants