任意ユーザのツイート収集

This commit is contained in:
ry.yamafuji 2025-09-16 17:16:42 +09:00
parent f1c4403b1a
commit ac9f5d9032

View File

@ -243,7 +243,15 @@ class XScraper:
# ---- example usage ----
async def search_tweets(self, query: str, limit: int = 50) -> List[Dict[str, Any]]:
"""キーワード検索で最新ツイートを収集"""
q = quote(query, safe="")
url = f"https://x.com/search?q={q}&src=typed_query&f=live"
first = await _goto_and_scrape(self.page, url)
return await _fill_with_scroll(self.page, first, limit)
async def user_latest_tweets(self, username: str, limit: int = 50) -> List[Dict[str, Any]]:
"""任意ユーザの最新ツイートを収集"""
url = f"https://x.com/{username.lstrip('@')}"
first = await _goto_and_scrape(self.page, url)
return await _fill_with_scroll(self.page, first, limit)