简单 python 爬虫(爬取小说网)


#https://blog.csdn.net/Isana_Yashiro/article/details/84582946
import requests
from bs4 import BeautifulSoup
target = 'https://www.biqukan.com/1_1094/5403177.html'
req = requests.get(url=target)
req.encoding='GBK'
html = req.text
soup = BeautifulSoup(html, 'html.parser')
texts = soup.select('.showtxt')
print(texts[0].text.replace(' ', '\n').replace('\xa0'*8, '\n'))


#有道翻译
import requests        #导入requests包
import json
def get_translate_date(word=None):
url = 'http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule'
From_data={'i':word,'from':'AUTO','to':'AUTO','smartresult':'dict','client':'fanyideskweb','salt':'15885798599693','sign':'f0571e9e3db6fecdcc228d7c7294e362','ts':'1588579859969','bv':'9d1e6a4f9d4241fb7947f623cc9e4efa','doctype':'json','version':'2.1','keyfrom':'fanyi.web','action':'FY_BY_REALTIME','typoResult':'false'}
#请求表单数据
response = requests.post(url,data=From_data)
#将Json格式字符串转字典
content = json.loads(response.text)
print(content)
#打印翻译后的数据
print(content['translateResult'][0][0]['tgt'])
if __name__=='__main__':
get_translate_date('我爱中国')
posted @   杨广伟  阅读(681)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示