Created
March 27, 2017 08:55
-
-
Save jamil666/79b12688d4988795bdfbf2b3ec257a69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import urllib.request | |
from prettytable import PrettyTable | |
List_of_Weapons = [] | |
URL_Shturm = "https://wf.mail.ru/wiki/index.php/%D0%9E%D1%80%D1%83%D0%B6%D0%B8%D0%B5_%D1%88%D1%82%D1%83%D1%80%D0%BC%D0%BE%D0%B2%D0%B8%D0%BA%D0%B0" | |
URL_Medik = "https://wf.mail.ru/wiki/index.php/%D0%9E%D1%80%D1%83%D0%B6%D0%B8%D0%B5_%D0%BC%D0%B5%D0%B4%D0%B8%D0%BA%D0%B0" | |
URL_Injener = "https://wf.mail.ru/wiki/index.php/%D0%9E%D1%80%D1%83%D0%B6%D0%B8%D0%B5_%D0%B8%D0%BD%D0%B6%D0%B5%D0%BD%D0%B5%D1%80%D0%B0" | |
URL_Sniper = "https://wf.mail.ru/wiki/index.php/%D0%9E%D1%80%D1%83%D0%B6%D0%B8%D0%B5_%D1%81%D0%BD%D0%B0%D0%B9%D0%BF%D0%B5%D1%80%D0%B0" | |
def get_html(url): # This function connects to html site. | |
response = urllib.request.urlopen(url) | |
return response.read() | |
def parse(html): # This function parse site and add output to CSV file | |
soup = BeautifulSoup(html, 'html5lib') # Create variable for soup | |
Klasses = soup.find("p") # Find klass of weapon | |
table = soup.find("table", class_="sortable") # Find weapon | |
for rows in table.find_all("tr"): | |
Columns = rows.find_all("td") | |
for Weapon in Columns[:1]: # 1 column | |
for Damage in Columns[1:2]: # 2 column | |
for RangeOfFire in Columns[2:3]: # 3 column | |
for RateOfFire in Columns[3:4]: # 4 column | |
for AccuracyInSight in Columns[4:5]: # 5 column | |
for AccuracyFromHip in Columns[5:6]: # 6 column | |
for Capacity in Columns[6:7]: # 7 column | |
for Ammunition in Columns[7:8]: # 8 column | |
for Recoil in Columns[8:9]: # 9 column | |
for klass in Klasses.find_all("b"): # Klass | |
List_of_Weapons.append({"Класс": klass.text, "Оружие": Weapon.text, | |
"Урон": Damage.text, | |
"Дальность стрельбы": RangeOfFire.text, | |
"Темп стрельбы": RateOfFire.text, | |
"Точность стрельбы в прицеле": AccuracyInSight.text, | |
"Точность стрельбы от бедра": AccuracyFromHip.text, | |
"Емкость магазина": Capacity.text, | |
"Боезапас": Ammunition.text, | |
"Отдача": Recoil.text[1::], | |
}) | |
parse(get_html(URL_Shturm)) | |
parse(get_html(URL_Injener)) | |
parse(get_html(URL_Medik)) | |
parse(get_html(URL_Sniper)) | |
Pretty = PrettyTable() # Create table | |
Pretty.field_names = ["Класс", "Оружие", "Урон", "Дальность стрельбы","Темп стрельбы", "Точность стрельбы в прицеле", | |
"Точность стрельбы от бедра", "Емкость магазина", "Боезапас", "Отдача"] | |
Search = input("Выберете оружие: ") | |
for item in List_of_Weapons[1::]: | |
if Search in item["Оружие"]: | |
Pretty.add_row((item["Класс"], item["Оружие"], item["Урон"], item["Дальность стрельбы"], | |
item["Темп стрельбы"], item["Точность стрельбы в прицеле"], item["Точность стрельбы от бедра"], | |
item["Емкость магазина"], item["Боезапас"], item["Отдача"])) | |
print(Pretty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment