114培訓(xùn)網(wǎng)歡迎您來(lái)到全國(guó)python學(xué)習(xí)中心!

13289378727

全國(guó)統(tǒng)一學(xué)習(xí)專線 9:00-21:00

不管你是待業(yè)還是失業(yè),在這個(gè)被互聯(lián)網(wǎng)圍繞的時(shí)代里,選擇php和python爬蟲(chóng),就多了一項(xiàng)技能,還怕找不到工作?,還怕不好找工作?小編就來(lái)告訴你這個(gè)專業(yè)的優(yōu)勢(shì)到底體現(xiàn)在哪里:整理java,python,php各自爬蟲(chóng)的寫法??。

1.整理java,python,php各自爬蟲(chóng)的寫法

最近被面試官問(wèn):會(huì)不會(huì)寫爬蟲(chóng)?我覺(jué)得我會(huì)用java,python,php三種語(yǔ)言寫法java/** * Http get請(qǐng)求 * @param httpUrl 連接 * @return 響應(yīng)數(shù)據(jù) */ public static String doGet(String httpUrl){ //鏈接 = null; is = null; br = null; result = new (); try { //創(chuàng)建連接 URL url = new URL(httpUrl); = () url.(); //設(shè)置請(qǐng)求方式 .("GET"); //設(shè)置連接超時(shí)時(shí)間 .(15000); //開(kāi)始連接 .connect(); //獲取響應(yīng)數(shù)據(jù) if (.() == 200) { //獲取返回的數(shù)據(jù) is = .(); if (null != is) { br = new (new (is, "utf8")); String temp = null; while (null != (temp = br.readLine())) { result.append(temp); } } } } catch ( e) { e.(); } finally { if (null != br) { try { br.close(); } catch ( e) { e.(); } } if (null != is) { try { is.close(); } catch ( e) { e.(); } } //關(guān)閉遠(yuǎn)程連接 .(); } return result.toString(); } public static void main(String[] args) { String url = " String s = doGet(url); String p1 = ".*\<h1 title="(?<jobname>.*?)"\>.*salary"\>(?<salary>.*?)\<\/span\>.*"text-city" href\=".*"\>(?<address>.*?)\<\/p\>" + ".*\<a ka\="job-detail-company_" href\="(?<comlink>.*?)" title="(?<comname>.*?)" target\="_blank"\>" + ".*\<div class\="job-sec"\>(?<content>.*?)\<\/div\>.*"; Pattern r1 = Pattern.compile(p1); Matcher matcher = r1.matcher(s); while (matcher.find()){ String jobname = matcher.group("jobname"); String salary = matcher.group("salary"); String address = matcher.group("address"); String comlink = matcher.group("comlink"); String comname = matcher.group("comname"); String content = matcher.group("content"); } }php$url = " $con = file_get_contents($url); $reg = ".*<h1 title="(.*?)"\>.*salary"\>(.*?)\<\/span\>.*"text-city" href\=".*"\>(.*?)\<\/p\>" + ".*\<a ka\="job-detail-company_" href\="(.*?)" title="(.*?)" target\="_blank"\>" + ".*\<div class\="job-sec"\>(.*?)\<\/div\>.*"; $result = preg_match_all($reg,$con,$match_result); var_dump($match_result);_url = ' headers={"User-Agent":""} postdata=urllib.parse.urlencode(data).encode('utf-8') req=urllib.request.Request(url=base_url,headers=headers,data=postdata,method='POST') response=urllib.request.urlopen(req).read() html=response.decode() results1 = re.findall('<td data-header="xxxxx" class="github-posi">.*?(d+).*?<div',html,re.DOTALL) 更多面試題:admix.md · 千年碼農(nóng)/匯總2021最全各行業(yè)面試題_面經(jīng)分享 - Gitee.com

就拿大數(shù)據(jù)說(shuō)話,優(yōu)勢(shì)一目了然,從事IT行業(yè),打開(kāi)IT行業(yè)的新大門,找到適合自己的培訓(xùn)機(jī)構(gòu),進(jìn)行專業(yè)和系統(tǒng)的學(xué)習(xí)。

溫馨提示:為不影響您的學(xué)業(yè),來(lái)校區(qū)前請(qǐng)先電話咨詢,方便我校安排相關(guān)的專業(yè)老師為您解答
相關(guān)資料
  • 作者最新文章
  • 在線報(bào)名
申請(qǐng)?jiān)嚶?tīng)課程

只要一個(gè)電話
我們免費(fèi)為您回電

姓名不能為空
手機(jī)號(hào)格式錯(cuò)誤