通过python脚本获取facebook的pageID,在界面展示

import requests
import re
from pywebio.platform.flask import webio_view
from flask import Flask
from pywebio.output import *
import pywebio.pin as pin

def get_id():
    put_markdown("## Get homepage PageID")
    pin.put_input(name="page_url",placeholder='eg:https://www.facebook.com/theoldhongkong/')
    def call():
        #配置代理
        proxies = {
            "http": "127.0.0.1:1080",
            "https": "127.0.0.1:1080",
        }
        headers = {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
        }
        url = pin.pin['page_url']
        if url:
            toast("Start get pageID...")
            res = requests.get(url, headers, proxies=proxies)
            source_html = res.text
            pattern = re.compile(r'"pageID":"\d+"')
            page_id = pattern.search(source_html).group().split(":")[-1].strip('"')
            if page_id:
                page_id = "https://www.facebook.com/" + page_id
                toast(page_id)
            else:
                toast("Get pageID fail!!!")
        else:
            toast("page url can't is null !")
    put_buttons(['Get pageID'], lambda page_id: call())

app = Flask(__name__)
app.add_url_rule('/getId', 'webio_view', webio_view(get_id),
                             methods=['GET','POST'])
app.run(host="0.0.0.0", port=5577, debug=True)

  

posted @ 2022-08-25 10:49  RoyFans  阅读(89)  评论(0编辑  收藏  举报