1 Star 0 Fork 183

格调@main / Python爬虫

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
爬取有道翻译 做英汉字典.py 863 Bytes
一键复制 编辑 原始数据 按行查看 历史
import requests
from fake_useragent import UserAgent
from pyquery import PyQuery as pq
ua=UserAgent()
headers={
'User-Agent':ua.random
}
def request_html(q):
url='http://dict.youdao.com/search?q={}&keyfrom=new-fanyi.smartResult'.format(q)
try:
response=requests.get(url,headers).text
return response
except Exception:
print('request error')
def The_dictionary(html):
doc=pq(html)
data=doc('#phrsListTab').items()
for i in data:
print(i.find('.trans-container').text())
The_phrase_phrase=input('是否查询此单词的短语(1.是,2,不是):')
if The_phrase_phrase == '1':
phrase=doc('#wordGroup').items()
for p in phrase:
print(p.find('.wordGroup').text())
a=input('要查询的单词:')
The_dictionary(request_html(a))
Python
1
https://gitee.com/czmain/python_reptilian.git
git@gitee.com:czmain/python_reptilian.git
czmain
python_reptilian
Python爬虫
master

搜索帮助