爬虫的一些工具。
Project description
download_tools
download_tools 下载工具库,也包括爬虫的一些工具。
安装
Required
pip install requests selenium
安装 download_tools
pip install download_tools
使用
下载文件
下载文件时,会先检查存储目录是否有同名文件,有就不下载。
download_url()
默认只使用requests获取,也可以selenium,需要浏览器firefox和Firefox驱动。
import download_tools as dt
dt.download_url('https://www.baidu.com', r'F:\test')
# 修改名称和增加后缀
dt.download_url('https://www.baidu.com', save_dir=r'F:\test', name='baidu',suffix='html')
download_url(url, save_dir, name=None, suffix=None,
headers=None , type='get', post_data=None,
has_selenium='no', sleep_time=0, headless=True)
参数:
url : str
链接
save_dir : str
保存的文件夹路径
name : str
文件名,默认None为url文件名
suffix : str
文件后缀,默认'txt'
type : str {'get','post'}
请求类型,使用'get'或 'post'加'post_data'
has_selenium : str {'both','only','no'}
'no'不使用selenium, 'both'先requests不行再selenium,'only'只使用selenium
download_str()
适用于已经获取到源代码,直接保存。当name参数为空时,使用当前日期时间做文件名。
import download_tools as dt
page_souce = '<p>测试</p>' dt.download_str(page_souce, r'F:\test', name='测试', suffix='html')
dt.download_str(page_souce, save_dir=r'F:\test')
headers
生成headers
import download_tools as dt
# 随机生成header
dt.Headers().get()
# 随机生成windows平台chrome浏览器headers
dt.Headers(os='win', browser="chrome", headers=True).get()
for i in range(10):
print(dt.Headers().get())
dtools.fake_headers fork from https://pypi.org/project/fake-headers/
修改:generate()函数名修改为get()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
download_tools-0.0.2.tar.gz
(7.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file download_tools-0.0.2.tar.gz.
File metadata
- Download URL: download_tools-0.0.2.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8129b3c5f1b796e8b4cf2974f6fa528e9537aed136720cbd713a4b051fdc909
|
|
| MD5 |
50e95a69192359b9f643432ca15d2ad5
|
|
| BLAKE2b-256 |
736dea243722caaaf770931d85341c66c5b44ad3cca70afebcd1aab8d8a6f190
|
File details
Details for the file download_tools-0.0.2-py3-none-any.whl.
File metadata
- Download URL: download_tools-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3361449f278a7eabe5033747fb3df48c3ac7ee4f7073a707528d9901b6b2c646
|
|
| MD5 |
e6b0adda7a2b2693b7cffdfc9d9e07de
|
|
| BLAKE2b-256 |
f7152112cc189e7e7ed4fbf1e33b871045b553208bc55f7c8fe7473264506cb5
|