python 3.10requests 2.25.1beautifulsoup4 4.11.2- Install requirements:
pip install -r requirements.txt - Suggestion: Install these extensions to see the results more clearly
- Markdown All in One. Press
ctrl+k vto preview markdown. - json
- Markdown All in One. Press
usage: app.py [-h] [-c CATEGORY]
Python web scrapper.
options:
-h, --help show this help message and exit
-c CATEGORY, --category CATEGORY
Category to scrape.
- Example:
python3 NguyenSyPhiLong.py -c khoa-hoc - List of categories:
the-gioi,xa-hoi,van-hoa,kinh-te,giao-duc,the-thao,giai-tri,phap-luat,khoa-hoc-cong-nghe,khoa-hoc,doi-song,xe-co,nha-dat
- Folder:
./multiprocessing/ - Run in parallel using python
multiprocessingmodule. - Run
python3 cores.pyto see how many cpus your system has. Example output:Number of cpu: 8 - Run
python3 app-parallel.pyto get the output. - Idea: The code defines a
scrape_categoryfunction that takes a category as input and performs the web scraping process. The main function creates a list of categories, creates a process pool with 6 workers, and maps thescrape_categoryfunction to each category in parallel using themultiprocessing.Pool.mapmethod. ThePool.closeandPool.joinmethods are used to free up resources after the scraping is complete.