import requestsfrom bs4 import BeautifulSoup#请求的urlurl = 'https://fanyi.baidu.com/sug'#输入的参数kw = input("请输入要翻译的单词:")#伪造UAheaders = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'}#定义参数params = {"kw": kw}#发送Request请求response = requests.get(url=url,params=params,headers=headers)response.encoding = "utf-8"#构造# soup = BeautifulSoup(response.text,"lxml")# <div class="dictionary-comment"># <p> <b>n.</b># <strong class="dict-comment-mean"># <span>猫</span><span class="dict-margin">;</span># <span>猫科动物</span># </strong># </p> <p> <b>vt.</b># <strong class="dict-comment-mean"># <span>把(锚)吊放在锚架上</span># </strong> </p># </div># result = soup.select('.dictionary-comment>p>strong>')# print(result)page_text = response.textprint(page_text)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。