mirror of
https://github.com/bellingcat/vk-url-scraper.git
synced 2026-06-11 21:08:37 +03:00
trying with token
This commit is contained in:
1
.github/workflows/main.yml
vendored
1
.github/workflows/main.yml
vendored
@@ -20,6 +20,7 @@ env:
|
||||
PYTHONPATH: ./
|
||||
VK_USERNAME: ${{ secrets.VK_USERNAME }}
|
||||
VK_PASSWORD: ${{ secrets.VK_PASSWORD }}
|
||||
VK_TOKEN: ${{ secrets.VK_TOKEN }}
|
||||
CAPTCHA_HANDLE_URL: ${{ secrets.CAPTCHA_HANDLE_URL }}
|
||||
|
||||
jobs:
|
||||
|
||||
@@ -17,7 +17,7 @@ vks = None
|
||||
|
||||
def test_login_success():
|
||||
global vks
|
||||
vks = VkScraper(os.environ["VK_USERNAME"], os.environ["VK_PASSWORD"])
|
||||
vks = VkScraper(os.environ["VK_USERNAME"], os.environ["VK_PASSWORD"], os.environ.get("VK_TOKEN"))
|
||||
|
||||
|
||||
def test_scrape_empty_urll():
|
||||
|
||||
@@ -38,10 +38,11 @@ class VkScraper:
|
||||
PHOTO_PATTERN = re.compile(r"(photo.{0,1}\d+_\d+)")
|
||||
VIDEO_PATTERN = re.compile(r"(video.{0,1}\d+_\d+)")
|
||||
|
||||
def __init__(self, username: str, password: str, captcha_handler=captcha_handler) -> None:
|
||||
def __init__(self, username: str, password: str, token: str = None, captcha_handler=captcha_handler) -> None:
|
||||
"""Initializes the scraper.
|
||||
|
||||
This function receives a username and password and performs authentication on vk.com to then call api endpoints
|
||||
This function receives a username and password (or access token) and performs
|
||||
authentication on vk.com to then call api endpoints. If token is passed, authentication will not be performed again.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -49,9 +50,12 @@ class VkScraper:
|
||||
Username on vk.com, can be a phone number or email
|
||||
password : str
|
||||
Matching password on vk.com
|
||||
token : str
|
||||
Access token received after authenticating, can be found in the vl_config.v2.json file
|
||||
"""
|
||||
self.session = vk_api.VkApi(username, password, captcha_handler=captcha_handler)
|
||||
self.session.auth(token_only=True)
|
||||
self.session = vk_api.VkApi(username, password, token=token, captcha_handler=captcha_handler)
|
||||
if token is None or len(token) == 0:
|
||||
self.session.auth(token_only=True)
|
||||
|
||||
def scrape(self, url: str) -> List:
|
||||
"""Scrapes a URL for multiple possibilities of inner links such as wall, video, photo, ...
|
||||
|
||||
Reference in New Issue
Block a user