How to use page_source method in pytractor

Best Python code snippet using pytractor_python

sourcecrawler.py

Source:sourcecrawler.py Github

copy

Full Screen

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__':...

Full Screen

Full Screen

tests_graficos.py

Source:tests_graficos.py Github

copy

Full Screen

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?"...

Full Screen

Full Screen

tests_equipe.py

Source:tests_equipe.py Github

copy

Full Screen

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...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytractor automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful