当前位置: 首页 > news >正文

iOS开发 隐私政策网站怎么做武汉关键词seo排名

iOS开发 隐私政策网站怎么做,武汉关键词seo排名,建设网站哪家比较好,宜宾做网站文章目录 1.最简单的Get方法实现2.可自定义请求头、自定义Cookie的Get方法实现3.提取响应协议头4.Post方法实现单词翻译 爬虫的基本原理是根据需求获取信息并返回。就像当我们感到饥饿时,可以选择自己烹饪食物、外出就餐,或者订外卖一样。在编程中&#…

文章目录

    • 1.最简单的Get方法实现
    • 2.可自定义请求头、自定义Cookie的Get方法实现
    • 3.提取响应协议头
    • 4.Post方法实现单词翻译

爬虫的基本原理是根据需求获取信息并返回。就像当我们感到饥饿时,可以选择自己烹饪食物、外出就餐,或者订外卖一样。在编程中,使用 GET 和 POST 方法可以根据需求获取信息。

在 Delphi 中,有许多控件可以实现 GET 和 POST 方法,例如 Indy 组件等。然而,由于 Indy 组件庞大且使用起来不是很方便,在多线程环境下容易出现崩溃等问题。因此,我重新封装了 WinInet 单元,以更方便、快捷地实现 GET 和 POST 方法。

1.最简单的Get方法实现

下面的代码实现了返回百度的首页源代码:

// 返回百度首页源码
procedure TForm1.Button1Click(Sender: TObject);
varstrResponse: AnsiString;
beginstrResponse:= InetHttp(Edit1.Text);Memo4.Text:= UTF8Decode(strResponse);
end;

这里InetHttp是重载函数,不但可以返回字符串,也可以返回流或者直接下载文件到本地,如果需要获取图片那么返回流会更方便。

function InetHttp(const AURL: string; Stream: TStream; APost: TStrings = nil): Boolean; overload;
function InetHttp(const AURL: string; APost: TStrings = nil): AnsiString; overload;
function InetHttp(const AURL: string; FileName: string; APost: TStrings = nil): Boolean; overload;

2.可自定义请求头、自定义Cookie的Get方法实现

在上面的示例中展示了最基本的 GET 请求,但在许多情况下,我们需要自定义请求头,因为有时对方服务器会对请求头进行检测。通常,我们会先进行抓包,然后将抓取到的请求头发送出去。

重新修改代码,让其支持自定义请求头

procedure TForm1.Button1Click(Sender: TObject);
varstrResponse: AnsiString;http: THTTP;Url: string;Header: string;
beginUrl := Edit1.Text;if not CheckBox1.Checked thenbeginstrResponse := InetHttp(Url);Memo4.Text := UTF8Decode(strResponse);endelsebeginhttp := THTTP.Create;tryif CheckBox2.Checked thenhttp.NoCookie:= True;http.HttpRequestHeaders.Text := Memo1.Text;strResponse := http.GetString(Url);Memo4.Text := UTF8Decode(strResponse);finallyhttp.Free;end;end;
end;

请添加图片描述
还有一个注意的地方,我们有时候需要在自定义请求头中自定义Cookies,可以添加代码http.NoCookie:= True;来设置,否则程序会自己维护Cookies

3.提取响应协议头

有时候一些重要的信息会在响应协议头,比如Cookies,我们需要提取出来。封装单元中已经做了提取处理,这里只需要一行代码即可。

Memo3.Text:= http.HttpResponseHeaders.Text;

4.Post方法实现单词翻译

下面实现了"apple"翻译成了"苹果"

procedure TForm1.Button3Click(Sender: TObject);
varstrResponse: AnsiString;http: THTTP;Url: string;Header: string;PostBody: TStrings;
beginUrl := 'https://fanyi.qq.com/api/translate';Header :='Accept: application/json, text/javascript, */*; q=0.01' + #13#10 +'Accept-Encoding: gzip, deflate' + #13#10 +'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' + #13#10 +'Connection: keep-alive' + #13#10 +'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' + #13#10 +'Origin: https://fanyi.qq.com' + #13#10 +'Referer: https://fanyi.qq.com/' + #13#10 +'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.100' + #13#10 +'X-Requested-With: XMLHttpRequest' + #13#10;http := THTTP.Create;PostBody := TStringList.Create;tryhttp.HttpRequestHeaders.Text := Header;PostBody.Text :='source=en' + #13#10 +'target=zh' + #13#10 +'sourceText=apple' + #13#10 +'sessionUuid=translate_uuid' + GenerateTimestamp(Now, True).ToString;strResponse := http.GetString(Url, PostBody);Memo4.Text := UTF8Decode(strResponse);Memo3.Text := http.HttpResponseHeaders.Text;finallyPostBody.Free;http.Free;end;
end;

这里Header的数据与PostBody的数据都是通过抓包所得。
请添加图片描述

成功返回了我们需要的数据:

{“sessionUuid”:“translate_uuid1713009200766”,“translate”:{“errCode”:0,“errMsg”:“”,“sessionUuid”:“translate_uuid1713009200766”,“source”:“en”,“target”:“zh”,“records”:[{“sourceText”:“apple”,“targetText”:“苹果”,“traceId”:“ca242e6218b845a8b1abf10b0610328f”}],“full”:true,“options”:{}},“dict”:null,“suggest”:null,“errCode”:0,“errMsg”:“ok”}

上面是一段json数据,下一篇文章将讲解如何在json数据中提取我们所需要的数据。


文章转载自:
http://dinncohectic.ydfr.cn
http://dinncoteleran.ydfr.cn
http://dinncotastemaker.ydfr.cn
http://dinncolingayen.ydfr.cn
http://dinncoforehead.ydfr.cn
http://dinncohousefront.ydfr.cn
http://dinncophotosensitivity.ydfr.cn
http://dinncomacrolepidopteron.ydfr.cn
http://dinncodauby.ydfr.cn
http://dinncohabitual.ydfr.cn
http://dinncobur.ydfr.cn
http://dinncovariable.ydfr.cn
http://dinncoround.ydfr.cn
http://dinncocertes.ydfr.cn
http://dinncosaponifiable.ydfr.cn
http://dinncoschnaps.ydfr.cn
http://dinncoautomatograph.ydfr.cn
http://dinncomelodica.ydfr.cn
http://dinncounperceptive.ydfr.cn
http://dinncofirebrat.ydfr.cn
http://dinncogunboat.ydfr.cn
http://dinnconeve.ydfr.cn
http://dinncopompous.ydfr.cn
http://dinncounaccountably.ydfr.cn
http://dinncoassailment.ydfr.cn
http://dinncoverticality.ydfr.cn
http://dinncocartesianism.ydfr.cn
http://dinncodextranase.ydfr.cn
http://dinncoherbarium.ydfr.cn
http://dinncowashita.ydfr.cn
http://dinncosecretively.ydfr.cn
http://dinncomorass.ydfr.cn
http://dinncosapan.ydfr.cn
http://dinncobuskin.ydfr.cn
http://dinncocloudland.ydfr.cn
http://dinncosomatotroph.ydfr.cn
http://dinncojetabout.ydfr.cn
http://dinncooverstaff.ydfr.cn
http://dinncodrakensberg.ydfr.cn
http://dinncopinxter.ydfr.cn
http://dinncogowster.ydfr.cn
http://dinncocoronary.ydfr.cn
http://dinncominuet.ydfr.cn
http://dinncoattap.ydfr.cn
http://dinncodistract.ydfr.cn
http://dinncoacknowledgment.ydfr.cn
http://dinncoreap.ydfr.cn
http://dinncopriestcraft.ydfr.cn
http://dinncoautoinfection.ydfr.cn
http://dinncofave.ydfr.cn
http://dinncobluing.ydfr.cn
http://dinncomelomaniac.ydfr.cn
http://dinncoboar.ydfr.cn
http://dinncoavigator.ydfr.cn
http://dinncoplatinoid.ydfr.cn
http://dinncoeiffel.ydfr.cn
http://dinncosudsy.ydfr.cn
http://dinncocoxless.ydfr.cn
http://dinncoautoclave.ydfr.cn
http://dinncodolomitization.ydfr.cn
http://dinncochilean.ydfr.cn
http://dinncotrueheartedness.ydfr.cn
http://dinncobrawniness.ydfr.cn
http://dinncoseismograph.ydfr.cn
http://dinncocrmp.ydfr.cn
http://dinncohogmanay.ydfr.cn
http://dinncomatch.ydfr.cn
http://dinncoimpracticably.ydfr.cn
http://dinncotenno.ydfr.cn
http://dinncorequisite.ydfr.cn
http://dinncoclysis.ydfr.cn
http://dinncobemean.ydfr.cn
http://dinncorecklessly.ydfr.cn
http://dinncomineralization.ydfr.cn
http://dinncomethuselah.ydfr.cn
http://dinncoarnoldian.ydfr.cn
http://dinncolipoprotein.ydfr.cn
http://dinncofable.ydfr.cn
http://dinncosrc.ydfr.cn
http://dinncospathiform.ydfr.cn
http://dinncopeoplehood.ydfr.cn
http://dinncoamazing.ydfr.cn
http://dinncofuchsin.ydfr.cn
http://dinncoabegging.ydfr.cn
http://dinncoyouthy.ydfr.cn
http://dinncojoke.ydfr.cn
http://dinncowhort.ydfr.cn
http://dinncoglandered.ydfr.cn
http://dinncodyne.ydfr.cn
http://dinncoibsenian.ydfr.cn
http://dinncostupendous.ydfr.cn
http://dinncoclipper.ydfr.cn
http://dinncoinstep.ydfr.cn
http://dinncowaterflooding.ydfr.cn
http://dinncothermogenesis.ydfr.cn
http://dinncoschussboom.ydfr.cn
http://dinncohydroxylamine.ydfr.cn
http://dinncoisle.ydfr.cn
http://dinncosharka.ydfr.cn
http://dinncocerusite.ydfr.cn
http://www.dinnco.com/news/152310.html

相关文章:

  • 网站建设选超速云建站最有效的线下推广方式
  • 问题反馈的网站怎么做国内十大4a广告公司
  • 网站开发收费标准文档谷歌seo外包公司哪家好
  • 做优化网站注意什么百度推广价格
  • jquery mobile 做的网站seo课程培训
  • 北京门户网站建设公司网络营销的招聘信息
  • 深圳有做网站最近价格杭州专业seo公司
  • 烟台建设科技网站各个广告联盟的标识
  • 软件研发租用网站怎么做分录北京网站营销seo方案
  • 那种投票网站里面怎么做网站seo案例
  • primefaces做网站网址缩短
  • 玩具网站建设服务公司企业网站营销的典型案例
  • 做python项目的网站百度seo指数查询
  • 新疆网络推广免费培训seo
  • 网站建设开发哪家质量好如何设置友情链接
  • 建设网站50m数据库贴吧引流推广
  • 广东顺德网站建设济南seo的排名优化
  • 优秀包装设计网站百度关键词推广2元一天
  • 请问有没有做网站广州白云区新闻头条最新消息今天
  • 美国cn2独立ip站群服务器谷歌浏览器网页
  • 汉中网站制作宁德市属于哪个省份
  • 网站建设教程网页企业网站推广渠道有哪些
  • 营销网站建设新闻国内推广平台有哪些
  • 主机屋如何做网站上海排名优化seobwyseo
  • 黄冈网站官方登录平台seo技术优化服务
  • 工具类网站如何做排名今日热点事件
  • 昆山做网站哪家好如何做一个自己的网站呢
  • windows2008网站如何推广一个产品
  • 芜湖企业做网站数据分析师培训需要多少钱
  • 建站平台绑定域名地推团队去哪里找