class Weibo:
def __init__(self, _browser: BrowserContext):
self._browser = _browser
pass
def get_weibo(self, id):
print('start get_weibo')
url = 'https://m.weibo.cn/u/' + id
page = self._browser.new_page()
page.goto(url)
page.wait_for_load_state()
time.sleep(2)
cards = page.locator('.card-wrap')
# page.pause()
for card in cards.all():
weibo_text = card.locator('.weibo-text')
text = weibo_text.inner_text()
print(text)
print('======')
pass
if __name__ == '__main__':
with sync_playwright() as p:
browser = p.chromium.launch_persistent_context(
user_data_dir=user_data_dir,
channel="msedge",
headless=False
)
print('start')
weibo = Weibo(browser)
weibo.get_weibo('5722964389')
print('end')
browser.close()
使用Python获取指定微博账号下的内容
- Python
- 5 days ago
- 1 min read
tool