首页 > 其他分享 >爬虫1 认识和基本爬取UA伪装

爬虫1 认识和基本爬取UA伪装

时间:2022-12-22 19:44:32浏览次数:33  
标签:data 爬虫 爬取 item listItem UA response

robots.txt 协议

君子协议

如果爬取了robots.txt 不允许被爬的东西,会封你IP,你还可以进局子。

可以在网站根目录下加上访问看下存在不,大网站一般是存在的。

百度翻译[练练手 UA 伪标]

# 作者:咸瑜
# 仅供学习使用!!!
import json

import requests

URL = "https://fanyi.baidu.com/sug"

# header UA 伪装
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.81 Safari/537.36 Edg/104.0.1293.47'}

key = input("输入要翻译的单词:")
# 参数
data = {
    "kw": key
}

response = requests.post(url=URL, data=data, headers=header).json()

for item in response:
    if type(response[item]) == list:
        for listItem in response[item]:
            print('单词:', listItem['k'], '    中文翻译:', listItem['v'])

image-20221222193806216

标签:data,爬虫,爬取,item,listItem,UA,response
From: https://www.cnblogs.com/bi-hu/p/16999468.html

相关文章