Download scrap.py from zxy0307/Python_06_Web_crawler: direct link, hf CLI and curl.
- Browser
- Download file 447 Bytes
-
https://huggingface.co/zxy0307/Python_06_Web_crawler/resolve/main/scrap.py
- Command line
-
hf download hf://zxy0307/Python_06_Web_crawler/scrap.py
-
curl -L -o scrap.py https://huggingface.co/zxy0307/Python_06_Web_crawler/resolve/main/scrap.py
447 Bytes
| """quote: 进行URL编码,发送中文请求""" | |
| from urllib.request import urlopen,Request | |
| from fake_useragent import UserAgent | |
| from urllib.parse import quote | |
| url = f'https://www.amap.com' | |
| # 随机生成用户代理 | |
| ua = UserAgent() | |
| headers = { | |
| 'User-Agent':ua.chrome | |
| } | |
| # 创建 request对象 | |
| req = Request(url,headers = headers) | |
| # 发送请求 | |
| resp = urlopen(req) | |
| with open("./gaode.html", 'w') as f: | |
| f.write(resp.read().decode()) |