trying with token

This commit is contained in:
msramalho
2022-06-21 14:16:54 +02:00
parent d96e0c0a3a
commit 90b72b6d22
3 changed files with 10 additions and 5 deletions

View File

@@ -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:

View File

@@ -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():

View File

@@ -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, ...