![last name generator last name generator](https://pics.onsizzle.com/oth-lyfe-goth-name-generator-first-name-initial-last-name-4327539.png)
# women's first names, one for men's first names, and one write ( record + " \n " ) # I'm calling the function 3 times to have 3 files: one for append ( column_text ) # the last step is to write the names into the file,įor record in records : f. capitalize () # store all the names in records list # but because the names in the table are writtenĬolumn_text = column. find ( "td" ) # to extract only text we can use. # contains the name I'm using find("td") methodĬolumn = row. # elements, but only the first td element I want to have many names, so Iįor row in rows : # in each row we want to find table data with a # many rows are there and decide how many names we find_all ( "tr" ) # now we want to loop over rows. # First we go through all the elements in tbody to findįor elem in tbody : rows = elem. # see that we have many and tag elements. Records = # if we take a look at the output of print(tbody) we can Print ( tbody ) # now it's time to store the data from the website.į = open ( file_name, "w+" ) # it creates a file in which find_all ( id = "myTable" ) # if we want to see the output in command line #it, we have to check the id of the table.
![last name generator last name generator](https://i.pinimg.com/736x/2d/b5/2a/2db52a6e98828eebb6631f0d16252c96--whats-your-name-game-what-is-your-name.jpg)
# whole HTML document printed in the command line. text, "html.parser" ) print ( soup ) # this line is also optional, only to see in command line raise_for_status () # extract text - now we have all the text from the page Print ( page ) # check if an error occurs get ( url ) # this line is not essential, but if we want to check But when I build something, I use them often to check if my solution is correct.įrom bs4 import BeautifulSoup import requests #create functionĭef get_data ( url, file_name ): # make a get request In my last draft, I don't have many or at all print statements. Let's build the scraper first and crate name_scraper.py file. To inspect the website, we need to open developer tools in the browser (chrome or firefox), and we need to check tags and ids. In order to do it, we have to inspect a website from which we want to acquire the data, and we need a bit of HTML knowledge. This method only retrieves data and has no other effects.īeautifulSoup is a library that helps to get data out of HTML or any other markup language. In this case, I'm using only one method GET to get data from a given address. HTTP client (for example web browser) makes a request (sends a message) which communicates to the server what action they want to perform. HTTP stands for Hypertext Transfer Protocol, and it enables communications between clients and servers. The requests library is used to send all kinds of HTTP requests. To do it, first, I'm creating a virtual environment using pipenv and installing those libraries.Įnter fullscreen mode Exit fullscreen mode I'm using two Python libraries: BeautifulSoup and requests. And I don't need to scrape the page each time I would like to randomly choose a name for a story character or mockup website. Why I'm storing data first? Because if we use scraper too often, some websites can block it completely. I'm storing them in three txt files, and then, in the next file, I'm creating a function that opens each file, reads it and randomly chooses one first name and one last name. In this exercise, I'm building a web scraper to get the most USA popular male and female first name and last names. learn to write tech articles and documentation.push my boundaries and start using more advanced features.The language of my choice (for now) is Python because I haven't been using it much recently. But now, and I want to go through all of them and write about it here. Some of them were pretty easy, but others were much difficult. When I started learning to code, I found a pretty long list of tasks to do.