Cov txheej txheem:
- Kauj Ruam 1: Sau Cov Khoom
- Kauj Ruam 2: Nrhiav Tus Thawj Coj Tsim nyog los Tsim Kev Sib Tham
- Kauj Ruam 3: Npaj Txoj Cai
- Kauj Ruam 4: Xa Cov Teeb Meem Zoo
- Kauj Ruam 5: Khaub Ncaws Mechanized
- Kauj Ruam 6: Ntsuas Lub Plawv
Video: Xav txog Ajax Lub Vev Xaib Nrog Asynchronous Login Form: 6 Cov Kauj Ruam (nrog Duab)
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:31
Qhov teeb meem: Xav txog cov cuab yeej tsis tso cai rau AJAX ID nkag mus pov thawj.
Cov lus qhia no yuav qhia koj yuav ua li cas nkag mus los ntawm AJAX daim ntawv siv Python thiab tus qauv hu ua Mechanize. Kab laug sab yog web automation cov haujlwm uas tau dhau los ua txoj hauv kev nrov rau tib neeg los khaws cov ntaub ntawv online. Lawv nkag mus ncig lub vev xaib sib sau cov ntaub ntawv muaj txiaj ntsig los txhawb cov tuam txhab web muaj zog tshaj plaws nyob ib puag ncig. Lwm tus nkag mus thiab sau cov ntaub ntawv tshwj xeeb los txhim kho kev txiav txim siab, lossis txheeb xyuas qhov tam sim no "hauv", lossis nrhiav txoj kev mus ncig uas pheej yig tshaj. Kab laug sab (web crawlers, webbots, lossis tshuaj ntsuam scrapers) yog qhov zoo rau tig HTML goop mus rau qee qhov zoo sib xws ntawm cov ntaub ntawv ntse, tab sis peb muaj teeb meem thaum nws los txog rau AJAX qhib lub vev xaib uas muaj JavaScript thiab cov ncuav qab zib tau qhib ua ntu uas tsis tuaj yeem siv tau nrog ib txwm muaj txheej ntawm cov cuab yeej xav tau. Hauv cov lus qhia no peb yuav nkag mus rau peb tus kheej nplooj ntawv ntawm pubmatic.com. Cov theem no yuav qhia koj txoj hauv kev ua raws, tab sis koj nplooj ntawv yuav txawv. Muaj kev lom zem!
Kauj Ruam 1: Sau Cov Khoom
Koj yuav tsum tau pib ntxiv koj cov peev txheej kev ua haujlwm. Koj yuav xav tau cov haujlwm hauv qab no. Siv lawv cov lus qhia los pab koj teeb tsa cov no… Nruab FirebugIt's Firefox addonInstall PythonGo to: python.orgGo to: python.orgInstall the Mechanize ModuleGet MechanizeGet MechanizeOther useful Splection tools: BeautifulSoup
Kauj Ruam 2: Nrhiav Tus Thawj Coj Tsim nyog los Tsim Kev Sib Tham
Ib tus kab laug sab zoo ua haujlwm zoo yuav nkag mus rau lub vev xaib zoo li nws yog lub browser raug tswj los ntawm tib neeg ua kom muaj kev qhia raws li nws yog keeb kwm tseeb. Ib feem ntawm kev sib cuam tshuam ntawm cov browser thiab server tshwm sim los ntawm GET thiab POST thov uas koj tuaj yeem pom hauv cov ntawv (cov ntaub ntawv no tsis tshua pom tshwm ntawm browser, tab sis tseem ceeb heev). Koj tuaj yeem saib qee cov ntaub ntawv no los ntawm nias Ctrl I (hauv firefox) kom qhib qhov Page Info window. Txhawm rau zais koj tus kheej ua tus browser me me koj yuav tsum txheeb xyuas koj tus kheej siv tib daim ntawv pov thawj yog tias koj tau sim nkag mus rau hauv pubmatic nrog javascript xiam oob khab hauv koj tus browser koj yuav tsis mus deb heev txij li kev xa rov qab tau ua tiav los ntawm javascript. Yog li txiav txim siab tias feem ntau kab laug sab browser tsis muaj javascript tus neeg txhais lus peb yuav tau txais los ntawm kev nkag mus los ntawm lwm txoj hauv kev. Cia peb pib los ntawm kev tau txais cov ntaub ntawv header xa los ntawm qhov browser thaum koj nyem xa. Yog tias qhov no yog qhov browser nkag mus yooj yim koj yuav siv Mechanize los ua daim ntawv thiab nyem xa. Cov ntaub ntawv nkag mus ib txwm raug kaw tsis pub dhau ib… tag thiab Mechanize yuav tuaj yeem xa qhov no thiab pov npav nplooj ntawv tom ntej yam tsis muaj teeb meem. Txij li thaum peb tsis muaj daim ntawv ua tiav daim ntawv, qhov ua haujlwm xa tawm tau ua los ntawm javascript. Cia saib xyuas pubmatic's submitForm muaj nuj nqi. Txhawm rau ua qhov no, xub qhib lub vev xaib hauv firefox thiab qhib lub foob pob hluav taws los ntawm nyem lub npauj npaim nyob rau sab xis sab xis. Tom qab ntawv nyem rau kab ntawv, theej tag nrho cov cai uas tshwm thiab muab nws tso rau hauv koj cov ntawv nyiam kho me ntsis ntawm software. Koj tuaj yeem tshem tawm tag nrho cov cai tshwj tsis yog muaj nuj nqi submitForm. Nws pib nrog kev ua haujlwm "submitForm (theform) {" thiab txhua yam hauv nruab nrab ntawm qhov no thiab cov haujlwm kaw kaw nkhaus "}". Ntawm kev txheeb xyuas cov haujlwm no thawj zaug peb pom tias qee qhov kev lees paub tshwm sim rov qab hloov pauv hu ua xmldoc uas tau muab cais ua xml. Nov yog qhov tseem ceeb ntawm AJAX nws tau xaiv cov neeg rau zaub mov thiab coj rov qab qee cov ntaub ntawv XML uas muaj cov ntoo ntawm cov ntaub ntawv. Lub node session_id muaj session_id yog tias kev lees paub ua tiav, koj tuaj yeem qhia qhov no los ntawm kev saib me ntsis ntawm cov cai: "yog (session_id! = Null) {// nkag mus tau zoo". Tam sim no peb xav tiv thaiv qhov me me ntawm javascript los ntawm kev coj peb mus rau txhua qhov chaw yog li peb tuaj yeem pom dab tsi tau tshaj tawm rau tus neeg rau zaub mov thaum lub sijhawm lees paub tseeb. Txhawm rau ua qhov no peb tawm tswv yim tawm ntawm lub qhov rais rov qab uas zoo li qhov no: "window.location = …". Txhawm rau tawm tswv yim tawm qhov no ntxiv ob qhov slashes ua ntej lawv zoo li: "//window.location …" qhov no tiv thaiv cov cai los ntawm kev khiav. Koj tuaj yeem rub tawm Javascript cov ntaub ntawv hauv qab no uas muaj cov kev kho no twb tau ua lawm. Luam thiab paste qhov kho me ntsis ntawm javascript rau hauv lub console windows sab xis thiab nyem rau. Qhov no hla tus javascript ua haujlwm twb muaj nyob hauv nplooj ntawv nrog peb cov tshiab. Tam sim no thaum koj ua tiav koj li ntawv pov thawj thiab nyem xa koj yuav tsum pom POST thiab GET header cov ntaub ntawv puv lub console, tab sis koj yuav tsis mus qhov twg. zoo li qhov no ua tau, luam thiab muab cov ntaub ntawv ntawd tso rau hauv phau ntawv sau.
Kauj Ruam 3: Npaj Txoj Cai
Ua ntej peb ntxiv cov headers tshiab peb tau pom cia peb tsim tus qauv Mechanize tus ID nkag mus nab npawb nab npawb. Peb tab tom ua qhov no rau ob qhov laj thawj, ua ntej peb muaj ib feem uas ua haujlwm ntxiv cov khoom tshiab rau thiab thib ob yog li koj pom koj li cas ib txwm nkag mus rau qhov tsis yog AJAX-y webpage. Op qhib notepad lossis sib npaug, thiab luam thiab muab ua raws Thaum koj ua tiav txuag nws raws li youfilename.py qhov chaw koj tuaj yeem nrhiav tau.#!/Usr/bin/nab hab sej#-*-coding: utf-8-*-#Pib nrog koj cov module ntshuam: los ntawm kev siv tshuab ntshuam Browser#Tsim koj li browser piv txwv los ntawm Browser () ua haujlwm hu; br = Browser ()#Teeb tus browser kom nws tsis quav ntsej cov kab laug sab.txt thov#Ua qhov no kom zoo, yog tias lub vev xaib tsis nyiam kab laug sab, lawv yuav chim siab kom pom koj therebr.set_handle_robots (Tsis tseeb) #Qhib nplooj ntawv koj xav nkag mus tobr.open ("https://pubmatic.com/04_betasignin.jsp") #Vim kuv paub lub npe lub npe, kuv tuaj yeem xaiv daim ntawv los ntawm namebr.select_form ("tus ID nkag mus")#Siv cov npe ntawm daim foos uas kuv tau sau lub npe ntawm daim ntawv elementbr ['email'] = "[email protected]" br ['password'] = "Asquid22"#br.submit () xa tawm daim ntawv thiab rub tawm nplooj ntawv ua tiav, koj tsim qhov browser tshiab piv txwv#cov lus teb hauv qab no muaj cov txiaj ntsig pageresponse = br.submit ()#Qhov no yuav luam tawm lub cev ntawm lub vev xaib tau txais#luam teb. nyeem ()
Kauj Ruam 4: Xa Cov Teeb Meem Zoo
Mechanize muaj qhov yooj yim ua haujlwm ntxiv cov headers rau headers POST, qhov no yuav ua rau peb pom tshwm rau tib lub browser uas koj tau siv nkag mus rau nplooj ntawv thawj zaug. Qhib cov ntawv nrog headers koj pom siv Firebug thiab kho cov ntawv no kom haum. Hloov txhua yam hauv nqe lus nrog cov khoom tsim nyog los ntawm cov npe hauv qab: USER_AGENT = "Mozilla/5.0 (X11; U; Linux i686; tr-TR; rv: 1.8.1.9) Gecko/20071102 Pardus/2007 Firefox/2.0.0.9" HOST = "pubmatic.com" ACCEPT = "text/xml, application/xml, application/xhtml+xml, text/html; q = 0.9, text/plain; q = 0.8, image/png, */ *; q = 0.5 "ACCEPT_LANGUAGE =" en-us, en; q = 0.5 "ACCEPT_ENCODING =" gzip, deflate "ACCEPT_CHARSET =" ISO-8859-1, utf-8; q = 0.7, *; q = 0.7 "KEEP_ALIVE =" 300 " CONNECTION = "khaws-ciaj sia" CONTENT_TYPE = "application/x-www-form-urlencoded" REFERER = "https://pubmatic.com/04_betasignin.jsp"CONTENT_LENGTH =" 60 "COOKIE =" utma = 103266945.1970108054.1210113004.121210872012.1212104072012.121210872012.12121072012.12121072017.12121072012.12121072012.12107 "CONNECTION =" keep-alive "; KADUSERCOOKIE = EA2C3249-E822-456E-847A-1FF0D4085A85; utmz = 103266945.1210113004.1.1.utmccn = (direct) | utmcsr = (ncaj) tsis-cache "CACHE_CONTROL =" tsis-cache "Qhov no tsim cov txheej txheem ntawm qhov sib txawv uas koj tuaj yeem siv los txuas ntxiv rau hauv lub hauv paus peb hauv tus lej no: br.add_header = [("Host", HOST)] br.add_headers = [("Tus neeg siv-tus sawv cev", USER_AGENT)] br.add_headers = [("Txais", ACCEPT)] br.add_header = [("Txais-Lus", ACCEPT_LANGUAGE)] br.add_headers = [("Txais-Nkag Siab", ACCEPT_ENCODING)] br.add_headers = [("Txais-Charset", ACCEPT_CHARSET)] br.add_header = [("Keep-Alive ", KEEP_ALIVE)] br.add_headers = [(" Kev Sib Txuas ", Kev Sib Txuas)] br.add_header = [(" Cov ntsiab lus-Hom ", CONTENT_TYPE)] br.add_header = [(" Referer ", REFERER)] br.add_header = [("Cov ntsiab lus-Ntev", CONTENT_LENGTH)] br.add_headers = [("Cookie", COOKIE)] br.add_headers = [("Pragma", PRAGMA)] br.add_headers = [("Cache-Control", CACHE_CONTROL)] Tam sim no thaum peb hu rau nplooj ntawv qhib ua haujlwm lub taub hau yuav raug xa mus rau tus neeg rau zaub mov ib yam. br.open ("https://pubmatic.com/04_betasignin.jsp")
Kauj Ruam 5: Khaub Ncaws Mechanized
Cov kauj ruam no yog vim lub tshuab ua haujlwm siv cov khoom qab zib yooj yim, tab sis nws tseem ceeb kom paub tias muaj dab tsi tshwm sim:
Thaum daim ntawv xa tuaj koj muaj txoj cai headers zoo li yog koj xa siv javascript muaj nuj nqi. Tom qab ntawd tus neeg rau zaub mov lees paub cov ntaub ntawv no thiab tsim ib ntu ID thiab khaws nws hauv cov khoom qab zib yog tias lub npe siv thiab tus lej nkag mus raug. Qhov xov xwm zoo yog Mechanize tau noj thiab rov ua cov ncuav qab zib kom koj tsis tas yuav txhawj xeeb txog kev xa thiab txais cov ncuav qab zib. Yog li thaum koj tsim ntu ID uas ua haujlwm koj tuaj yeem nkag mus rau cov tswv cuab tsuas yog ntu ntawm lub vev xaib.
Kauj Ruam 6: Ntsuas Lub Plawv
Tam sim no uas peb tau txais kev sib tham ID thiab Mechanize khaws nws rau hauv nws cov ncuav qab zib peb tuaj yeem ua raws javascript kom pom qhov twg peb yuav tsum mus. Saib sab hauv "yog (session_id! = Null) {// ID nkag mus tau zoo" kom pom qhov mus rau qhov ua tiav. Saib lub qhov rais hloov chaw chaws: "yog (adurlbase.search (/pubmatic.com/)! = -1) {window.location =" https://pubmatic.com/05_homeloggedin.jsp " +"? V = " + Lej.random ()*10000; " peb pom tias peb yuav tsum mus rau lub vev xaib nyob ntawm https://pubmatic.com/05_homeloggedin.jsp?v=some tus lej tsis raug. Yog li cia peb tsuas yog tsim tus lej tsis raug rau nkag mus thiab tsim qhov browser tshiab piv txwv los nyeem nplooj ntawv qhib tshiab: response2 = br.open ("https://pubmatic.com/05_homeloggedin.jsp?v=2703") Thiab qhov ntawd yuav tsum yog nws. Tam sim no koj cov cai tau ua tiav, los ntawm kev siv lub taub hau kom raug thiab cov neeg ua haujlwm kho cov khoom qab zib tam sim no peb tuaj yeem nkag mus rau sab hauv ntawm pubmatic. Txhawm rau ua hom no nab hab sej 2.5 thiab tom qab ntawv filepath mus rau.py cov ntaub ntawv.
Pom zoo:
$ 10 Lub Vev Xaib Lub Vev Xaib Kho: 5 Kauj Ruam (nrog Duab)
$ 10 Lub Vev Xaib Lub Vev Xaib Tsis Zoo: Zoo, kuv tau ua nws dua. Kuv tau tawg kuv qhov screen. Rau cov ntawm koj uas yuav nco tau, kuv tau ua qhov no tsuas yog ib xyoos dhau los thiab xav tau kev txhim kho ib ntus kom coj kuv mus txog thaum kuv tuaj yeem hloov pauv cov muab kev pabcuam thiab tau txais xov tooj tshiab. Nws tau ua haujlwm zoo, nws tau kav rau
Lub Vev Xaib Tswj Lub Vev Xaib Box: 4 Kauj Ruam
Lub Vev Xaib Tswj Lub Vev Xaib Box: Qhov no yog lub thawv xauv uas tuaj yeem qhib tau los ntawm kev qhia sai ntawm lub vev xaib. Qhov no txhais tau tias, koj tuaj yeem kaw cov khoom tam sim ntawd hauv lub thawv thiab tsuas yog nkag mus rau lawv thaum ib tus neeg nkag mus rau kab lus muab nkag rau ntawm lub vev xaib pej xeem. Vim li cas ib tus xav tau qhov no? Nov yog ib qho ex
Txhua Yam Txog Kev Tsim Lub Vev Xaib Lub Vev Xaib: 5 Kauj Ruam
Txhua Yam Txog Kev Tsim Lub Vev Xaib Lub Vev Xaib: Lub vev xaib pub dawb no yog daim ntawv uas koj siv los npaj phiaj xwm kev tsim kho cov ntsiab lus zoo ua kom pom tseeb cov ntsiab lus lub vev xaib. Daim qauv txheej txheem no tau tsim nrog kev yooj yim siv cov khoom siv hauv Microsoft Excel txawm hais tias muaj ntau yam software sib txawv
Ua Lub Vev Xaib Txuas Tus Neeg Hlau (rau Txog $ 500) (siv Arduino thiab Netbook): 6 Cov Kauj Ruam (nrog Duab)
Ua Lub Vev Xaib Sib Txuas Robot (Txog Txog $ 500) (siv Arduino thiab Netbook): Cov lus qhia no yuav qhia koj yuav tsim koj li cas los tsim koj tus kheej Lub Vev Xaib Txuas Nrog (siv Arduino micro-controller thiab Asus eee pc) .Vim li cas koj thiaj xav tau Lub Vev Xaib Txuas nrog Neeg Hlau? Ua si nrog ntawm cov hoob kawm. Tsav koj tus neeg hlau los ntawm hla chav lossis hla suav
Lub hauv paus tseem ceeb ntawm Lub Vev Xaib-raws li Lub Vev Xaib: 7 Kauj Ruam
Cov Hauv Paus Ntawm Lub Vev Xaib-raws li Lub Vev Xaib: Cov lus qhia no yuav qhia koj cov hauv paus ntawm kev tsim lub vev xaib nrog divs li cas. Vim tias cov ntxhuav siv rau kev teeb tsa yog qhov phem!: PTo kom nkag siab cov lus qhia no, koj yuav tsum paub qhov yooj yim html thiab css. Yog tias koj tsis nkag siab qee yam, xav tias dawb rau