Created
May 11, 2018 14:08
-
-
Save St1muL045/418ff21340ee687d2fc8946d90082929 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
import requests | |
import xml.etree.ElementTree as ET | |
import os | |
file_path = "test.csv" | |
def getData(url): | |
UserAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 YaBrowser/18.3.1.1232 Yowser/2.5 Safari/537.36' | |
result = requests.get(url, headers={'User-Agent': UserAgent}) | |
return result | |
def writeData(item): | |
with open(file_path, "a", encoding='utf-8') as file: | |
print("new line - " + item.find('title').text + "|" + item.find('pubDate').text) | |
file.write(item.find('title').text + "|" + item.find('link').text + "|" + | |
item.find('description').text.replace("\n", "") + "|" + item.find('pubDate').text + "\n") | |
if __name__ == '__main__': | |
if not os.path.exists(file_path): | |
open(file_path, 'tw', encoding='utf-8') | |
url = 'http://zakupki.gov.ru/epz/order/smp/rss' | |
result = getData(url) | |
root = ET.fromstring(result.text) | |
lines = root.findall('.//item') | |
text = open(file_path, "r", encoding='utf-8').read() | |
for item in lines: | |
if item.find('title').text not in text: | |
writeData(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment