How to use get_beautiful_soup method in SeleniumBase

Best Python code snippet using SeleniumBase

test_directory_lists.py

Source:test_directory_lists.py Github

copy

Full Screen

...4from dirhunt.processors import ProcessIndexOfRequest5from dirhunt.tests.base import CrawlerTestBase6class DirectoryListsTestBase(CrawlerTestBase):7 html = ''8 def get_beautiful_soup(self, html=None):9 html = html or self.html10 return BeautifulSoup(html, 'html.parser')11 def get_processor(self):12 return ProcessIndexOfRequest(None, self.get_crawler_url())13class TestApacheDirectoryLists(DirectoryListsTestBase, unittest.TestCase):14 html = """15 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">16 <html>17 <head>18 <title>Index of /wp-includes</title>19 </head>20 <body>21 <h1>Index of /wp-includes</h1>22 <pre><img src="/__apache/blank.gif" alt="Icon "> <a href="?C=N;O=D">Name</a>23 <a href="?C=M;O=A">Last modified</a> <a href="?C=S;O=A">Size</a> 24 <a href="?C=D;O=A">Description</a><hr>25 <img src="/__ovh_icons/back.gif" alt="[PARENTDIR]"> <a href="/">Parent Directory</a> - 26 <img src="/__apache/folder.gif" alt="[DIR]"> <a href="ID3/">ID3/</a> 2015-09-15 14:58 - 27 <img src="/__apache/folder.gif" alt="[DIR]"> <a href="IXR/">IXR/</a> 2018-02-16 14:29 - 28 <img src="/__apache/unknown.gif" alt="[ ]"> <a href="author-template.php">author-template.php</a> 29 2018-02-16 14:29 16K 30 <img src="/__apache/unknown.gif" alt="[ ]"> <a href="bookmark-template.php">bookmark-template.php</a> 31 2018-02-16 14:29 11K 32 </pre>33 </body></html> 34 """35 def test_is_applicable(self):36 beautiful_soup = self.get_beautiful_soup()37 self.assertTrue(ApacheDirectoryList.is_applicable(self.html, self.get_crawler_url(), beautiful_soup))38 def test_is_not_applicable(self):39 beautiful_soup = self.get_beautiful_soup(TestCommonDirectoryList.html)40 self.assertFalse(ApacheDirectoryList.is_applicable(TestCommonDirectoryList.html,41 self.get_crawler_url(), beautiful_soup))42 def test_get_links(self):43 directory_list = ApacheDirectoryList(self.get_processor())44 links = directory_list.get_links(self.html, self.get_beautiful_soup())45 test_data = [(link.url, link.extra) for link in links]46 self.assertEqual(test_data, [47 ('http://domain.com/', {}),48 ('http://domain.com/path/ID3/', {'created_at': '2015-09-15 14:58'}),49 ('http://domain.com/path/IXR/', {'created_at': '2018-02-16 14:29'}),50 ('http://domain.com/path/author-template.php', {'created_at': '2018-02-16 14:29', 'filesize': '16K'}),51 ('http://domain.com/path/bookmark-template.php', {'created_at': '2018-02-16 14:29', 'filesize': '11K'}),52 ])53class TestCommonDirectoryList(DirectoryListsTestBase, unittest.TestCase):54 html = """55 <html><head><title>Index Of</title></head><body>56 <a href="..">Top</a>57 <a href="dir/">dir</a>58 <a href="foo.php">foo.php</a>59 <a href="error_log">error_log</a>60 <a href="/spam/eggs">Eggs</a></body></html>61 """62 urls = [63 'http://domain.com/',64 'http://domain.com/path/dir/',65 'http://domain.com/path/foo.php',66 'http://domain.com/path/error_log',67 'http://domain.com/spam/eggs',68 ]69 def test_process(self):70 directory_list = CommonDirectoryList(self.get_processor())71 links = directory_list.get_links(self.html, self.get_beautiful_soup())72 urls = [link.url for link in links]73 self.assertEqual(urls, self.urls)74 def test_is_applicable(self):75 beautiful_soup = self.get_beautiful_soup()...

Full Screen

Full Screen

Parser.py

Source:Parser.py Github

copy

Full Screen

2import requests3class WeatherParser:4 def __init__(self):5 self.url = "https://sinoptik.com.ru/погода-"6 def get_beautiful_soup(self, city):7 request = requests.get(self.url + city)8 return bs4.BeautifulSoup(request.text, "html.parser")9 def get_current_temperature(self, city='москва'):10 beautiful_soup = self.get_beautiful_soup(city)11 return beautiful_soup.select('.weather__article_main_temp')[0].getText().replace('\n', '')12 def get_forecast(self, city='москва'):13 beautiful_soup = self.get_beautiful_soup(city)14 diapason_list = [15 i.getText().replace('\n\n\n', ' ').replace('\n\n', ' ').replace('\n', '').strip()16 for i in beautiful_soup.select('.weather__content_tab-temperature')17 ]18 date_list = [19 i.getText() for i in beautiful_soup.select('.weather__content_tab-date')20 ]21 month_list = [22 i.getText() for i in beautiful_soup.select('.weather__content_tab-month')23 ]24 result = [25 (i[0] + ' ' + i[1], i[2]) for i in zip(date_list, month_list, diapason_list)26 ]27 return result28 def get_today_temperature(self, city='москва'):29 beautiful_soup = self.get_beautiful_soup(city)30 time_list = [31 i.getText().replace('\n', '')32 for i in beautiful_soup.select('.weather__article_main_right-table .table__time_hours')33 ]34 temperature_list = [35 i.getText()36 for i in beautiful_soup.select('.weather__article_main_right-table .table__temp')37 ]38 result = list(zip(time_list, temperature_list))...

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