vk-url-scraper


Namevk-url-scraper JSON
Version 0.3.30 PyPI version JSON
download
home_pageNone
SummaryScrape VK URLs to fetch info and media - python API or command line tool.
upload_time2024-07-16 15:22:17
maintainerNone
docs_urlNone
authorBellingcat
requires_python>=3.10
licenseMIT
keywords scraper vk vkontakte vk-api media-downloader
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # vk-url-scraper
Python library to scrape data, and especially media links like videos and photos, from vk.com URLs.


[![PyPI version](https://badge.fury.io/py/vk-url-scraper.svg)](https://badge.fury.io/py/vk-url-scraper)
[![PyPI download month](https://img.shields.io/pypi/dm/vk-url-scraper.svg)](https://pypi.python.org/pypi/vk-url-scraper/)
[![Documentation Status](https://readthedocs.org/projects/vk-url-scraper/badge/?version=latest)](https://vk-url-scraper.readthedocs.io/en/latest/?badge=latest)


You can use it via the [command line](#command-line-usage) or as a [python library](#python-library-usage), check the **[documentation](https://vk-url-scraper.readthedocs.io/en/latest/)**.

## Installation
You can install the most recent release from [pypi](https://pypi.org/project/vk-url-scraper/) via `pip install vk-url-scraper`.

Currently you need to manually install one dependency (as it is installed from github and not pypi):
`pip install git+https://github.com/python273/vk_api.git@b99dac0ec2f832a6c4b20bde49869e7229ce4742`

To use the library you will need a valid username/password combination for vk.com. 

## Command line usage
```bash
# run this to learn more about the parameters
vk_url_scraper --help

# scrape a URL and get the JSON result in the console
vk_url_scraper --username "username here" --password "password here" --urls https://vk.com/wall12345_6789
# OR
vk_url_scraper -u "username here" -p "password here" --urls https://vk.com/wall12345_6789
# you can also have multiple urls
vk_url_scraper -u "username here" -p "password here" --urls https://vk.com/wall12345_6789 https://vk.com/photo-12345_6789 https://vk.com/video12345_6789

# you can pass a token as well to avoid always authenticating 
# and possibly getting captcha prompts
# you can fetch the token from the vk_config.v2.json file generated under by searching for "access_token"
vk_url_scraper -u "username" -p "password" -t "vktoken goes here" --urls https://vk.com/wall12345_6789

# save the JSON output into a file
vk_url_scraper -u "username here" -p "password here" --urls https://vk.com/wall12345_6789 > output.json

# download any photos or videos found in these URLS
# this will use or create an output/ folder and dump the files there
vk_url_scraper -u "username here" -p "password here" --download --urls https://vk.com/wall12345_6789
# or
vk_url_scraper -u "username here" -p "password here" -d --urls https://vk.com/wall12345_6789
```

## Python library usage
```python
from vk_url_scraper import VkScraper

vks = VkScraper("username", "password")

# scrape any "photo" URL
res = vks.scrape("https://vk.com/photo1_278184324?rev=1")

# scrape any "wall" URL
res = vks.scrape("https://vk.com/wall-1_398461")

# scrape any "video" URL
res = vks.scrape("https://vk.com/video-6596301_145810025")
print(res[0]["text"]) # eg: -> to get the text from code
```

```python
# Every scrape* function returns a list of dict like
{
	"id": "wall_id",
	"text": "text in this post" ,
	"datetime": utc datetime of post,
	"attachments": {
		# if photo, video, link exists
		"photo": [list of urls with max quality],
		"video": [list of urls with max quality],
		"link": [list of urls with max quality],
	},
	"payload": "original JSON response converted to dict which you can parse for more data
}
```

see [docs] for all available functions. 

### TODO
* scrape album links
* scrape profile links
* docs online from sphinx

## Development
(more info in [CONTRIBUTING.md](CONTRIBUTING.md)).

1. setup dev environment with `pip install -r dev-requirements.txt` or `pipenv install -r dev-requirements.txt`
1. setup environment with `pip install -r requirements.txt` or `pipenv install -r requirements.txt`
2. To run all checks to `make run-checks` (fixes style) or individually
   1. To fix style: `black .` and `isort .` -> `flake8 .` to validate lint
   2. To do type checking: `mypy .`
   3. To test: `pytest .` (`pytest -v --color=yes --doctest-modules tests/ vk_url_scraper/` to use verbose, colors, and test docstring examples)
3. `make docs` to generate shpynx docs -> edit [config.py](docs/source/conf.py) if needed

To test the command line interface available in [__main__.py](__vk_url_scraper/__main__.py) you need to pass the `-m` option to python like so: `python -m vk_url_scraper -u "" -p "" --urls ...`


## Releasing new version
1. edit [version.py](vk_url_scraper/version.py) with proper versioning
2. make sure to run `pipenv run pip freeze > requirements.txt` if you manage libs with pipenv
   1. if the hardcoded version of [vk_api](https://github.com/python273/vk_api) is still being used, then you must comment/remove that line from the generated requirements file and instruct users to manually install the version from the source as pypi does not allow repo/commit tags. Additionally, add the latest released version, currently `vk-api==11.9.9`. 
3. run `./scripts/release.sh` to create a tag and push, alternatively
   1. `git tag vx.y.z` to tag version
   2. `git push origin vx.y.z` -> this will trigger workflow and put project on [pypi](https://pypi.org/project/vk-url-scraper/)
4. go to https://readthedocs.org/ to deploy new docs version (if webhook is not setup)

### Fixing a failed release

If for some reason the GitHub Actions release workflow failed with an error that needs to be fixed, you'll have to delete both the tag and corresponding release from GitHub. After you've pushed a fix, delete the tag from your local clone with

```bash
git tag -l | xargs git tag -d && git fetch -t
```

Then repeat the steps above.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "vk-url-scraper",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "scraper, vk, vkontakte, vk-api, media-downloader",
    "author": "Bellingcat",
    "author_email": "tech@bellingcat.com",
    "download_url": "https://files.pythonhosted.org/packages/b9/4c/7deed94de31c3d75edcf963eb3ad1cc5e7872faab28138aa2469e018fe66/vk_url_scraper-0.3.30.tar.gz",
    "platform": null,
    "description": "# vk-url-scraper\nPython library to scrape data, and especially media links like videos and photos, from vk.com URLs.\n\n\n[![PyPI version](https://badge.fury.io/py/vk-url-scraper.svg)](https://badge.fury.io/py/vk-url-scraper)\n[![PyPI download month](https://img.shields.io/pypi/dm/vk-url-scraper.svg)](https://pypi.python.org/pypi/vk-url-scraper/)\n[![Documentation Status](https://readthedocs.org/projects/vk-url-scraper/badge/?version=latest)](https://vk-url-scraper.readthedocs.io/en/latest/?badge=latest)\n\n\nYou can use it via the [command line](#command-line-usage) or as a [python library](#python-library-usage), check the **[documentation](https://vk-url-scraper.readthedocs.io/en/latest/)**.\n\n## Installation\nYou can install the most recent release from [pypi](https://pypi.org/project/vk-url-scraper/) via `pip install vk-url-scraper`.\n\nCurrently you need to manually install one dependency (as it is installed from github and not pypi):\n`pip install git+https://github.com/python273/vk_api.git@b99dac0ec2f832a6c4b20bde49869e7229ce4742`\n\nTo use the library you will need a valid username/password combination for vk.com. \n\n## Command line usage\n```bash\n# run this to learn more about the parameters\nvk_url_scraper --help\n\n# scrape a URL and get the JSON result in the console\nvk_url_scraper --username \"username here\" --password \"password here\" --urls https://vk.com/wall12345_6789\n# OR\nvk_url_scraper -u \"username here\" -p \"password here\" --urls https://vk.com/wall12345_6789\n# you can also have multiple urls\nvk_url_scraper -u \"username here\" -p \"password here\" --urls https://vk.com/wall12345_6789 https://vk.com/photo-12345_6789 https://vk.com/video12345_6789\n\n# you can pass a token as well to avoid always authenticating \n# and possibly getting captcha prompts\n# you can fetch the token from the vk_config.v2.json file generated under by searching for \"access_token\"\nvk_url_scraper -u \"username\" -p \"password\" -t \"vktoken goes here\" --urls https://vk.com/wall12345_6789\n\n# save the JSON output into a file\nvk_url_scraper -u \"username here\" -p \"password here\" --urls https://vk.com/wall12345_6789 > output.json\n\n# download any photos or videos found in these URLS\n# this will use or create an output/ folder and dump the files there\nvk_url_scraper -u \"username here\" -p \"password here\" --download --urls https://vk.com/wall12345_6789\n# or\nvk_url_scraper -u \"username here\" -p \"password here\" -d --urls https://vk.com/wall12345_6789\n```\n\n## Python library usage\n```python\nfrom vk_url_scraper import VkScraper\n\nvks = VkScraper(\"username\", \"password\")\n\n# scrape any \"photo\" URL\nres = vks.scrape(\"https://vk.com/photo1_278184324?rev=1\")\n\n# scrape any \"wall\" URL\nres = vks.scrape(\"https://vk.com/wall-1_398461\")\n\n# scrape any \"video\" URL\nres = vks.scrape(\"https://vk.com/video-6596301_145810025\")\nprint(res[0][\"text\"]) # eg: -> to get the text from code\n```\n\n```python\n# Every scrape* function returns a list of dict like\n{\n\t\"id\": \"wall_id\",\n\t\"text\": \"text in this post\" ,\n\t\"datetime\": utc datetime of post,\n\t\"attachments\": {\n\t\t# if photo, video, link exists\n\t\t\"photo\": [list of urls with max quality],\n\t\t\"video\": [list of urls with max quality],\n\t\t\"link\": [list of urls with max quality],\n\t},\n\t\"payload\": \"original JSON response converted to dict which you can parse for more data\n}\n```\n\nsee [docs] for all available functions. \n\n### TODO\n* scrape album links\n* scrape profile links\n* docs online from sphinx\n\n## Development\n(more info in [CONTRIBUTING.md](CONTRIBUTING.md)).\n\n1. setup dev environment with `pip install -r dev-requirements.txt` or `pipenv install -r dev-requirements.txt`\n1. setup environment with `pip install -r requirements.txt` or `pipenv install -r requirements.txt`\n2. To run all checks to `make run-checks` (fixes style) or individually\n   1. To fix style: `black .` and `isort .` -> `flake8 .` to validate lint\n   2. To do type checking: `mypy .`\n   3. To test: `pytest .` (`pytest -v --color=yes --doctest-modules tests/ vk_url_scraper/` to use verbose, colors, and test docstring examples)\n3. `make docs` to generate shpynx docs -> edit [config.py](docs/source/conf.py) if needed\n\nTo test the command line interface available in [__main__.py](__vk_url_scraper/__main__.py) you need to pass the `-m` option to python like so: `python -m vk_url_scraper -u \"\" -p \"\" --urls ...`\n\n\n## Releasing new version\n1. edit [version.py](vk_url_scraper/version.py) with proper versioning\n2. make sure to run `pipenv run pip freeze > requirements.txt` if you manage libs with pipenv\n   1. if the hardcoded version of [vk_api](https://github.com/python273/vk_api) is still being used, then you must comment/remove that line from the generated requirements file and instruct users to manually install the version from the source as pypi does not allow repo/commit tags. Additionally, add the latest released version, currently `vk-api==11.9.9`. \n3. run `./scripts/release.sh` to create a tag and push, alternatively\n   1. `git tag vx.y.z` to tag version\n   2. `git push origin vx.y.z` -> this will trigger workflow and put project on [pypi](https://pypi.org/project/vk-url-scraper/)\n4. go to https://readthedocs.org/ to deploy new docs version (if webhook is not setup)\n\n### Fixing a failed release\n\nIf for some reason the GitHub Actions release workflow failed with an error that needs to be fixed, you'll have to delete both the tag and corresponding release from GitHub. After you've pushed a fix, delete the tag from your local clone with\n\n```bash\ngit tag -l | xargs git tag -d && git fetch -t\n```\n\nThen repeat the steps above.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Scrape VK URLs to fetch info and media - python API or command line tool.",
    "version": "0.3.30",
    "project_urls": {
        "Code": "https://github.com/bellingcat/vk-url-scraper",
        "Documentation": "https://vk-url-scraper.readthedocs.io/en/latest/"
    },
    "split_keywords": [
        "scraper",
        " vk",
        " vkontakte",
        " vk-api",
        " media-downloader"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1126855770b2fa445ae09620eccc71e7f8415da184f878bd1232a0d02742210a",
                "md5": "eb7bf03366d2a8cdf87848ea60adba48",
                "sha256": "2e83e690844bb9b04772fae56bed2d9654780ca23132155e63de4ed9bde70c23"
            },
            "downloads": -1,
            "filename": "vk_url_scraper-0.3.30-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb7bf03366d2a8cdf87848ea60adba48",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 11975,
            "upload_time": "2024-07-16T15:22:14",
            "upload_time_iso_8601": "2024-07-16T15:22:14.981337Z",
            "url": "https://files.pythonhosted.org/packages/11/26/855770b2fa445ae09620eccc71e7f8415da184f878bd1232a0d02742210a/vk_url_scraper-0.3.30-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b94c7deed94de31c3d75edcf963eb3ad1cc5e7872faab28138aa2469e018fe66",
                "md5": "51f0a6b490e0fec0e61af5910c27b0db",
                "sha256": "6616c8fbe6ea6f8cbe4605898a89d1173a579ed6a9da5410dba80269d708fcb1"
            },
            "downloads": -1,
            "filename": "vk_url_scraper-0.3.30.tar.gz",
            "has_sig": false,
            "md5_digest": "51f0a6b490e0fec0e61af5910c27b0db",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 15068,
            "upload_time": "2024-07-16T15:22:17",
            "upload_time_iso_8601": "2024-07-16T15:22:17.323821Z",
            "url": "https://files.pythonhosted.org/packages/b9/4c/7deed94de31c3d75edcf963eb3ad1cc5e7872faab28138aa2469e018fe66/vk_url_scraper-0.3.30.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-16 15:22:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bellingcat",
    "github_project": "vk-url-scraper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "vk-url-scraper"
}
        
Elapsed time: 4.30094s