Best Python code snippet using pytractor_python
sourcecrawler.py
Source:sourcecrawler.py
1# coding=UTF-82import urllib23import requests4from pyquery import PyQuery as pq5from connectsql import *6def main():7 kplant_crawler()8def kplant_crawler():9 res = requests.get("http://kplant.biodiv.tw/æ ¡åæ¤ç©é¦é .htm")10 res.encoding = 'utf-8'11 page = pq(res.text)12 # page.encoding = 'unicode'13 page_content = page('font').text()14 page_source = page_content.split(' ')15 # page_source_url = []16 page_removedata = [u"è³½ä¼¯ç ´å¸", u"éµè§", u"è¦å¤·è¥", u"éæ§", u"é樺", u"å±±è¶è±", u"æ¨æ¨¹", u"éµä»è", u"ç½è±æ·±å±±éç¡ä¸¹", u"檳æ¦", u"å±±è§éº»", u"ç·¬æ¢è±", u"éé´è±", u"風é´è±", u"å±±ææ·", u"å¥ç°æ",17 u"é¦ç梨", u"ç®æ ¹è¯", u"é迦", u"æ´å¤", u"æ²¹å å©", u"æ²¹æ", u"ç´«è", u"ç´«èè", u"è©æ樹", u"å¹è", u"çè¼",18 u"åè¼è±", u"çä¾è", u"é¾è·è", u"é¾ç¼", u"ç¨è¡è", u"çæºå", u"åªæè¯", u"濱åºè", u"檵æ¨", u"ç¹è",19 u"å°¼æ³ç¾ç±ç°«", u"æµ·ç´
è±", u"ç´«æ¢
", u"é¯å°è±", u"å·ä¸æ°è", u"çèè±", u"èç½", u"ç", u"è´é¦", u"è¶",20 u"è¶åç", u"è¶åç", u"è¶åé»", u"è¯èè", u"è¯è·", u"é»è½è", u"ééæ", u"é»ç¨", u"ç¨é»", u"å·ä¸æ°æ¨èå",21 u"ç½", u"æ¡", u"é»æ§¿", u"馬æå·´æ ", u"馬ã¼å
", u"çæ¿", u"馬çºä¸¹", u"éæ¤", u"èæ¤", u"éèæ¥ ", u"éæ´²å°ç¾å",22 u"é«å±±ç¿»ç½è", u"åèå°¤å å©", u"åèç¯ç¯è", u"é«å±±é
¢æ¼¿è", u"åèé±å§è¨", u"ç°æ¨", u"å°ç£æ´æ¨¹", u"ç³é", u"åæ¹å¤§å±±åæ壺",23 u"å馬é½è§", u"ç´è³", u"æ¥æ¨¹", u"æ¦æ¨¹", u"å¿è溲ç", u"交è®æ¨", u"æå
è", u"æ¥æ¬å±±æ¡è±", u"è½ç«¿ç«¹", u"è½æ§ç«¹",24 u"æ¥æ¬æè±", u"å
èææ¨", u"å
èç³æ¥ ", u"éè¢è±", u"æ¥æ¬åè¡", u"é§ç¤¾æ«»", u"åºå°èéç¡ä¸¹", u"åæ¦", u"éºæ ¼æµ·æ£ ",25 u"æ¥æ¬æ¥¨æ¥ ", u"å¯è±è§éº»", u"è
ºè±æ¯è¼", u"ææ¡", u"樹", u"ææ¡", u"èé§ä¼¯è±", u"寶å¡é¾è¹è±", u"èè", u"ææ¥çè¢",26 u"èè±", u"èç¡ä¸¹", u"æ¨æ²¹æ¡", u"æ¨æ¥è", u"ææ ¸æ¨", u"èèªæ¤°å", u"æ¨éº»é»", u"èå©", u"èè", u"æ¨è¯", u"檬æ",27 u"æ¨èå0", u"æ¯å¬çç", u"å¤è±ç´«è¤", u"èè±å", u"ççè", u"é¦ç", u"馬è¯", u"çæ¤", u"æ¯æ±æéµ", u"å°å°¾é³³", u"è嶼å殼æ¡",28 u"åºæ ¼", u"éæ±é¾", u"é
ªæ¢¨", u"æ³èæ°´ç°è¡£", u"èçé´", u"ç°èç´
ç ", u"é·å
¬é", u"çè±é¢¨è¼ªè", u"éµåæ¨", u"ç°æ¨",29 u"è¶è¶", u"æ°´ä»ç¾å", u"éµå
é", u"ç¾é¨", u"éµç·è", u"éµè§", u"æ°´æ³æ¨¹", u"竹æ", u"çç è", u"æ¦æ¨¹", u"ç¾å¸¶ä¾", u"æ§æ¨¹",30 u"ç´°èé¶é¤å", u"滿ç¦æ¨", u"æ¼¢èéè
¥è", u"æ¬æ¨¨", u"èç©è", u"è®èæ¨", u"è¹ä»è", u"è¡æ¡", u"大水è", u"æ°´èé´", u"è¾è",31 u"ç¦æ»¿æ¨", u"è±ç´
鹿åç¾å", u"西å°åº¦æ«»æ¡", u"ç´
è±æ", u"å
åå©", u"ç¿ è¸è", u"æ¬ä»æ¨¹", u"ç«ç°ç¾å", u"西æ´èè", u"西æ´æ¤´æ¨¹",32 u"ç´
è±ä¸èè", u"ç¿ é²è", u"ç¿ èæ¨", u"çªå大é", u"ç´
è±ç ´å¸æ¨", u"èºç£å¤©åæ", u"éè¡æ¡", u"è±ç´«éç¡ä¸¹", u"çç½è¤",33 u"çç®è", u"çèè", u"å
é¯è²çè®", u"å
è²è", u"è±ç´
åæ¡", u"éç¡ä¸¹èå·æ°´éº»", u"è", u"é¦é", u"èå°èè£", u"èºç£", u"å°æ±ç«åºæ¨", u"ååæ¨", u"å°æ±æ¿",34 u"èºç£é¼ 麴è", u"åºèçè", u"n"]35 del page_source [0:19]36 del page_source [len(page_source)-1]37 for index in range(page_source.count(u'\r\n')):38 page_source.remove(u'\r\n')39 for index in range(page_source.count(u'')):40 page_source.remove(u'')41 for index in page_removedata:42 page_source.remove(index)43 s = page_source.index(u')')44 page_source[s-1] = page_source[s-1] + page_source[s]45 del page_source[s]46 s = page_source.index(u'ç®')47 page_source[s-1] = page_source[s-1] + page_source[s]48 del page_source[s]49 s = page_source.index(u'ç®')50 page_source[s-1] = page_source[s-1] + page_source[s]51 del page_source[s]52 s = page_source.index(u'è¤')53 page_source[s-1] = page_source[s-1] + page_source[s]54 del page_source[s]55 s = page_source.index(u'樹')56 page_source[s-1] = page_source[s-1] + page_source[s]57 del page_source[s]58 s = page_source.index(u'å§')59 page_source[s-1] = page_source[s-1] + page_source[s]60 del page_source[s]61 page_source.remove(u"å±±é»ç®")62 s = page_source.index(u"檫樹")63 page_source[s] = u"å°ç£æª«æ¨¹"64 s = page_source.index(u"çç± æ¤")65 page_source[s] = u"風é´è¾£æ¤"66 s = page_source.index(u"é«å±±ç¹¡çè¤")67 page_source[s] = u"é«å±±è¤ç¹¡ç"68 s = page_source.index(u"å¿èæ°´èè·")69 page_source[s] = u"ä¼ç風輪è"70 s = page_source.index(u"çè±è麻")71 page_source[s] = u"æ·¡ç´«ç´
è±ç£¨ç¤è"72 s = page_source.index(u"è·èè±")73 page_source[s] = u"è·å
è±"74 s = page_source.index(u"è§é³ç«¹(è¬è竹)")75 page_source[s] = u"è§é³ç«¹"76 s = page_source.index(u"ç´
è±ç³èç³è")77 page_source[s] = u"ç´
è±ç³è"78 s = page_source.index(u"ç£äºèæ¾")79 page_source[s-1] = page_source[s-1] + page_source[s]80 del page_source[s]81 s = page_source.index(u"åå¡")82 page_source[s] = page_source[s] + page_source[s+1]83 del page_source[s+1]84 s = page_source.index(u"ç´«è«")85 page_source[s] = page_source[s] + page_source[s+1]86 del page_source[s+1]87 s = page_source.index(u"è¥è")88 page_source[s] = page_source[s] + page_source[s+1]89 del page_source[s+1]90 s = page_source.index(u"èºç£")91 page_source[s] = page_source[s] + page_source[s+1]92 del page_source[s+1]93 spec_source = [u"èæ樹", u"èè", u"é¾ç¼", u"éå
è
¸", u"ç³ç«¹(è½ç«¿ç«¹)", u"ç¾
æ¼¢æ¾", u"å
è 樹", u"å¯ç©æ¡æ¢",94 u"éºéºè±", u"彩è²çè", u"åæ¡æ³èè", u"æè²", u"æç²è±", u"桶é¤è¤", u"æ°´æ³",95 u"ç¾ç¼è¤", u"å·å¤§æ", u"è·", u"ç¦ç¥¿æ¡", u"ç´
è±é¼ å°¾è", u"çè"]96 spec_source_url = [u"http://kplant.biodiv.tw/" + spec_source[0] + u"/èæ.htm",97 u"http://kplant.biodiv.tw/" + spec_source[1] + u"/" + spec_source[1] + u"920529.htm",98 u"http://kplant.biodiv.tw/" + spec_source[2] + u"0/" + spec_source[2] + u".htm",99 u"http://kplant.biodiv.tw/馬è/" + spec_source[3] + u".htm",100 u"http://kplant.biodiv.tw/è½ç«¿ç«¹/ç³ç«¹.htm",101 u"http://kplant.biodiv.tw/" + spec_source[5] + u"/" + spec_source[5] + u"920601.htm",102 u"http://kplant.biodiv.tw/" + spec_source[6] + u"/" + spec_source[6] + u"920706.htm",103 u"http://kplant.biodiv.tw/å°ç£è±/" + spec_source[7] + u".htm",104 u"http://kplant.biodiv.tw/" + spec_source[8] + u"/" + spec_source[8] + u"-910716.htm",105 u"http://kplant.biodiv.tw/" + spec_source[9] + u"/page_01.htm",106 u"http://kplant.biodiv.tw/" + spec_source[10] + u"/åæ¡å±±æ³èè.htm",107 u"http://kplant.biodiv.tw/ç å/" + spec_source[11] + ".htm",108 u"http://kplant.biodiv.tw/" + spec_source[12] + u"/" + spec_source[12] + u"920528.htm",109 u"http://kplant.biodiv.tw/" + spec_source[13] + u"/å°ç£é¼ æ.htm",110 u"http://kplant.biodiv.tw/" + spec_source[14] + u"/" + spec_source[14] + u"-910716.htm",111 u"http://kplant.biodiv.tw/éç¼è¤/" + spec_source[15] + u".htm",112 u"http://kplant.biodiv.tw/é¦æ/" + spec_source[16] + u".htm",113 u"http://kplant.biodiv.tw/" + spec_source[17] + u"/" + spec_source[17] + u"920529.htm",114 u"http://kplant.biodiv.tw/" + spec_source[18] + u"/" + spec_source[18] + u"-910716.htm",115 u"http://kplant.biodiv.tw/æ±åè±/" + spec_source[19] + u".htm",116 "http://kplant.biodiv.tw/çè/åºèçè.htm"]117 [conn, cur] = connectdb() 118 for index in page_source:119 tempstr = ""120 if index in spec_source:121 tempstr = spec_source_url[spec_source.index(index)]122 else:123 tempstr = "http://kplant.biodiv.tw/" + index + "/" + index + ".htm"124 # page_source_url.append(tempstr)125 # print (tempstr)126 insertdata(conn, cur, "datasource", ["source", "url"], ["http://kplant.biodiv.tw/", tempstr])127 # res2 = requests.get("http://kplant.biodiv.tw/å±±è¶è±/è¶è±ç®é.htm")128 # res2.encoding = 'big5'129 # page2 = pq(res2.text)130 # page_content2 = []131 # for index_row in range(3,18):132 # page_content2.append(page('body > table > tr:nth-child(' + str(index_row) + ') > td:nth-child(1)').text())133 # page_content2.append(page('body > table > tr:nth-child(' + str(index_row) + ') > td:nth-child(2)').text())134 # # print page_content135 # # print page_content2136 # for index_row2 in range(3,12):137 # page_content2.append(page('body > table > tr:nth-child(' + str(index_row) + ') > td:nth-child(3)').text())138 # del page_content2[2]139 # for index in page_content2:140 # tempstr = ""141 # tempstr = "http://kplant.biodiv.tw/å±±è¶è±/" + index + "/" + index + ".htm"142 # # page_source_url.append(tempstr)143 # # print (tempstr)144 # insertdata(conn, cur, "datasource", ["source", "url"], ["\'http://kplant.biodiv.tw/\'", "\'" + tempstr + "\'"])145 # closedb(conn,cur)146# èè147# é¾ç¼148# éå
è
¸149# ç³ç«¹(è½ç«¿ç«¹)150# ç¾
æ¼¢æ¾151# å
è 樹152# å¯ç©æ¡æ¢153# éºéºè±154# 彩è²çè155# åæ¡æ³èè156# æè²157# æç²è±158# 桶é¤è¤159# æ¿å160# æ°´æ³161# ç¾ç¼è¤162# å·å¤§æ163# è·164# ç¦ç¥¿æ¡165# ç´
è±é¼ å°¾è166#主ç¨å¼å¾é裡éå§167if __name__ == '__main__':...
tests_graficos.py
Source:tests_graficos.py
1from django.test import TestCase2from django.test import Client3from selenium import webdriver4from webdriver_manager.firefox import GeckoDriverManager5from selenium.webdriver.common.keys import Keys6from selenium.webdriver.firefox.options import Options7# Create your tests here.8class GraficosTestCase(TestCase):9 10 def setUp(self):11 options = Options()12 options.headless = True13 self.driver = webdriver.Firefox(options=options, executable_path=GeckoDriverManager().install())14 def tearDown(self):15 self.driver.close()16 17 def test_pagina_chapadao(self):18 self.driver.get('http://127.0.0.1:8000/graficos/chapadao')19 titulo = "Observatório UFJ Covid-19 - Gráficos (Caçu)"20 assert titulo in self.driver.title21 assert "Todas as categorias" in self.driver.page_source22 assert "Monitorados" in self.driver.page_source23 assert "Rede Social Oficial da Prefeitura de Caçu" in self.driver.page_source24 25 def test_pagina_chapadao(self):26 self.driver.get('http://127.0.0.1:8000/graficos/chapadao')27 titulo = "Observatório UFJ Covid-19 - Gráficos (Chapadão do Céu)"28 assert titulo in self.driver.title29 assert "Todas as categorias" in self.driver.page_source30 assert "Monitorados" in self.driver.page_source31 assert "Secretaria de Saúde de Chapadão do Céu" in self.driver.page_source32 33 def test_titulo_jatai(self):34 self.driver.get('http://127.0.0.1:8000/graficos/jatai')35 titulo = "Observatório UFJ Covid-19 - Gráficos (JataÃ)"36 assert titulo in self.driver.title37 assert "Todas as categorias" in self.driver.page_source38 assert "Monitorados" in self.driver.page_source39 assert "Secretaria de Saúde de JataÃ" in self.driver.page_source40 41 def test_titulo_mineiros(self):42 self.driver.get('http://127.0.0.1:8000/graficos/mineiros')43 titulo = "Observatório UFJ Covid-19 - Gráficos (Mineiros)"44 assert titulo in self.driver.title45 assert "Todas as categorias" in self.driver.page_source46 assert "Monitorados" in self.driver.page_source47 assert "Secretaria de Saúde de Mineiros" in self.driver.page_source48 def test_titulo_montividiu(self):49 self.driver.get('http://127.0.0.1:8000/graficos/montividiu')50 titulo = "Observatório UFJ Covid-19 - Gráficos (Montividiu)"51 assert titulo in self.driver.title52 assert "Todas as categorias" in self.driver.page_source53 assert "Monitorados" in self.driver.page_source54 assert "Rede Social Oficial da Prefeitura de Montividiu" in self.driver.page_source55 def test_titulo_rioverde(self): 56 self.driver.get('http://127.0.0.1:8000/graficos/rioverde')57 titulo = "Observatório UFJ Covid-19 - Gráficos (Rio Verde)"58 assert titulo in self.driver.title59 assert "Todas as categorias" in self.driver.page_source60 assert "Monitorados" in self.driver.page_source61 assert "Secretaria de Saúde de Rio Verde" in self.driver.page_source62 def test_titulo_santahelena(self): 63 self.driver.get('http://127.0.0.1:8000/graficos/santahelena')64 titulo = "Observatório UFJ Covid-19 - Gráficos (Santa Helena)"65 assert titulo in self.driver.title66 assert "Todas as categorias" in self.driver.page_source67 assert "Monitorados" in self.driver.page_source68 assert "Secretaria de Saúde de Santa Helena" in self.driver.page_source69 """ def test_titulo_comparacao(self): 70 self.driver.get('http://127.0.0.1:8000/comparacao')71 titulo = "Observatório UFJ Covid-19 - Comparação entre as cidades"72 assert titulo in self.driver.title """73 def test_titulo_comoSaoCriados(self): 74 self.driver.get('http://127.0.0.1:8000/como-sao-criados')75 titulo = "Observatório UFJ Covid-19 - Como são criados?"...
tests_equipe.py
Source:tests_equipe.py
1from django.test import TestCase2from django.test import Client3from selenium import webdriver4from webdriver_manager.firefox import GeckoDriverManager5from selenium.webdriver.common.keys import Keys6from selenium.webdriver.firefox.options import Options7# Create your tests here.8class EquipeTestCase(TestCase):9 10 def setUp(self):11 options = Options()12 options.headless = True13 self.driver = webdriver.Firefox(options=options, executable_path=GeckoDriverManager().install())14 def tearDown(self):15 self.driver.close()16 def test_equipe(self):17 self.driver.get('http://127.0.0.1:8000/equipe')18 assert "CrÃscilla Rezende" in self.driver.page_source19 assert "Diego Costa" in self.driver.page_source20 assert "Douglas Cedrim" in self.driver.page_source21 assert "Dyeimys Correa" in self.driver.page_source22 assert "Edlaine Vilela" in self.driver.page_source23 assert "Esdras L. Bispo Jr." in self.driver.page_source24 assert "Felipe Nedopetalski" in self.driver.page_source25 assert "Franciny Medeiros" in self.driver.page_source26 assert "Gabriel Santos" in self.driver.page_source27 assert "Joslaine Jeske" in self.driver.page_source28 assert "Luiz Pascoal" in self.driver.page_source29 assert "Manuel Ferreira" in self.driver.page_source30 assert "Marcelo Freitas" in self.driver.page_source31 assert "Marcos Alves" in self.driver.page_source32 assert "Márcio Lopes" in self.driver.page_source33 assert "Paulo Freitas" in self.driver.page_source34 assert "Zaqueu Souza" in self.driver.page_source35 assert "#TodosContraoCorona" in self.driver.page_source36 assert "Covid Goiás" in self.driver.page_source...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!