当前位置:网站首页>Web crawler technology creates its own Youdao dictionary
Web crawler technology creates its own Youdao dictionary
2022-07-18 22:31:00 【Lan Zhou Qianfan】
Here we talk about reptile related technologies , use python Language to achieve .python The powerful library provides us with many conveniences , Its unique language characteristics are deeply loved by the majority of ape friends . today , Introduce how to use python Web crawler technology to input your own Youdao Dictionary . 1: utilize Google Let's check some source code of Youdao official website
First, open Youdao's official website , Right click , There are options to check , We click to check , Click again network, Enter information in the box to translate , On the right network There will be changes in the future . as follows :
2: Let's look for relevant information , Code blocks related to our input . Let's click on method Here are some ways , Among them is get,post, If you don't find method, stay name Right click under the same box to find method The tab of , Click to . Let's click on a post The name before the method , The following appears , Pictured :
Let's look at the code taken down here , These include URL, Request header , Requested method , Status code , And the address , These are familiar basic in the field of reptiles Request URL: http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule Request Method: POST Status Code: 200 OK Remote Address: 220.181.76.84:80 Referrer Policy: no-referrer-when-downgrade What do we need ? Keep looking down , look for fromdata:, Here's what we're looking for , Of course, what we are looking for may be different , But you're looking for post Medium fromdata, Because the program needs i: woaibian from: AUTO to: AUTO smartresult: dict client: fanyideskweb salt: 15971347706367 sign: 6ad80e525096fac4d1d2d8276439147a lts: 1597134770636 bv: 7b07590bbf1761eedb1ff6dbfac3c1f0 doctype: json version: 2.1 keyfrom: fanyi.web action: FY_BY_REALTlME Let's look at the code first :
"""
designer : Jiang Guangdao
function : Crawl Youdao website content to realize your own dictionary
version : 1.0
date: 08/08/2020
"""
import urllib.request # Import urlib Medium request modular
import urllib.parse #parse It's analytic
import json #json It's a format
text = input(" Please input the content to be translated :")
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"# Be careful , This url If there is 0_ Or is it _0 dependent , Can be removed , This seems to be related to the anti reptile mechanism , I've tried it myself .
head={}# Here to simulate the browser
head["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"
data = {}#data It's a dictionary form , This is exactly what we need to extract
data["i"]= text
data["from"]= "AUTO"
data["to"]="AUTO"
data["smartresult"]= "dict"
data["client"]= "fanyideskweb"
data["salt"]= "15968687717172"
data["sign"]= "ffbf6f4c0c2001ae735f6fb95de58a04"
data["lts"]= "1596868771717"
data["bv"]= "7b07590bbf1761eedb1ff6dbfac3c1f0"
data["doctype"]= "json"
data["version"]= "2.1"
data["keyfrom"]="fanyi.web"
data["action"]= "FY_BY_CLICKBUTTION"
data = urllib.parse.urlencode(data).encode("utf-8")#data Switch here
rep = urllib.request.Request(url,data,head) # Here comes data, The request mode changes to post, Here is the visit
reponse = urllib.request.urlopen(rep)
html = reponse.read().decode("utf-8")# Set the code
target = json.loads(html)
html_ = target["translateResult"]
html__ = html_[0][0]
print(" Translation results ",html__["tgt"])My program tests are as follows :
The other thing I want to say is this ,python It also has a Translation Library , But its nature has its limitations , Here I also give the code :
"""
designer : Jiang Guangdao
function : Use of translation module
version : 1.0
date : 04/08/2020
"""
import os
from translate import Translator
Translator = Translator(from_lang="chinese",to_lang="english")
message__ = input(" Please enter the information to be translated ")
translation = Translator.translate(message__)
print(translation)See did not think of simple , But in fact, this translation is slow , My tests are as follows :
Welcome to leave a message , I wish you all learn programming well !
边栏推荐
- Student 985: why is C language still taught in schools| Send books at the end of the text
- WTL first window
- uniapp基础知识
- JS handwritten sort
- 高性价比模型 TSM,用 2D 的成本达到 3D 的效果
- Huawei od JS log sorting
- Sword finger offer 44 [a bit in the number sequence] [100%, 100%]
- 华为 机考js 素数之积
- How does MySQL execute SQL statements
- 【AI工程】02-AI工程(AI Engineering)面面观
猜你喜欢

SFF1602-MHCHXM超快恢复二极管SFF1602

uniapp基础知识

Lingo solves the maximum (small) value of piecewise function

Why is the count () method of MySQL so slow?

狂神redis笔记01

After reading this article, I will teach you to play with vulnhub, the penetration test target machine -- evilbox one

SCI paper submission process

Developers share the initial experience of tinyms, a high-level API tool of mindspire!

Four knapsack problems of dynamic programming

LINGO求解分段函数最大(小)值
随机推荐
Towhee daily model weekly report
What kind of wireless Bluetooth headset is good? Bluetooth headset with the best comprehensive performance
在匿名内部类中访问局部变量
Uniapp Basics
Accéder aux variables locales dans une classe interne anonyme
Why is the count () method of MySQL so slow?
The 100 billion yuan universe market is the new driving force of soul and Yingke
Domestic light! High score spatiotemporal representation learning model uniformer
Cmu15445 (fall 2019) project 4 - logging & Recovery details
[UCOS III source code analysis] - memory management mechanism
DOM operation in reverse order, interview questions
开发者分享 | MindSpore高阶API工具TinyMS初体验!
Innovation Center launch! Congratulations to Jiahua Wulian cloud for obtaining mindspire certification!
Results of shooting competition Huawei od JS
[UCOS III source code analysis] - task creation
Lingo solves the maximum (small) value of piecewise function
Graduation season -- common interview questions in database
图像、视频、3D 数据一把抓,不挑食的 AI 模型 Omnivore !
华为 机考js 素数之积
[UCOS III source code analysis] - event flag group