0

as i am new to python i am expecting help the people who have experience on that. i am having problems that how to apply proxy in the following code .i mean ,i wan to apply proxy in order to execute the following source code(the following source code is working without proxy ) Ref:https://pypi.python.org/pypi/sumy

<code>
from __future__ import absolute_import
from __future__ import division, print_function, unicode_literals
from sumy.parsers.html import HtmlParser
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
from sumy.summarizers.lsa import LsaSummarizer as Summarizer
from sumy.nlp.stemmers import Stemmer
from sumy.utils import get_stop_words
LANGUAGE = "czech"
SENTENCES_COUNT = 10

if __name__ == "__main__":
    url = "http://www.zsstritezuct.estranky.cz/clanky/predmety/cteni/jak-naucit-dite-spravne-cist.html"
    parser = HtmlParser.from_url(url, Tokenizer(LANGUAGE))
    # or for plain text files
    # parser = PlaintextParser.from_file("document.txt", Tokenizer(LANGUAGE))
    stemmer = Stemmer(LANGUAGE)

    summarizer = Summarizer(stemmer)
    summarizer.stop_words = get_stop_words(LANGUAGE)

    for sentence in summarizer(parser.document, SENTENCES_COUNT):
        print(sentence)
</code>


For an example with  a working source code that how to apply proxy
ex:
<code>
HTTP_PROXY = {
        "http": "xxx.xxx.xxx.xxx:8800",
        "https": "xxx.xxx.xxx.xxx:8800",
    }
fetch = requests.get("http://www.independent.co.uk/news/uk/politics/barack-obama-says-david-cameron-allowed-libya-to-become-a-s-show-a6923976.html", proxies=HTTP_PROXY)
    proxy_lookup = requests.get("https://httpbin.org/ip", proxies=HTTP_PROXY)

    html = BeautifulSoup(fetch.content, 'html.parser') #full content # lxml
    meta_title = html.title.string
</code>

Thanks in advance
2
  • So you are doing 2 different things here, you are trying to summarize zsstritezuct.estranky.cz and then below have something completely different. Are you trying to summarize www.independent.co.uk? Which part is not working for you? Commented Mar 11, 2016 at 5:40
  • yes.i want to apply proxy concept for the summarizing script. Commented Mar 11, 2016 at 5:58

1 Answer 1

1

Ok so what you need to do is change one line within sumy.py. Go here https://github.com/miso-belica/sumy/blob/dev/sumy/utils.py .

In sumy/utils.py(you'll have to find this in your python/scripts folder most likely).

The function:

def fetch_url(url):
    with closing(requests.get(url, headers=_HTTP_HEADERS)) as response:
        response.raise_for_status()
        return response.content

change to:

def fetch_url(url):
   HTTP_PROXY = {
        "http": "xxx.xxx.xxx.xxx:8800",
        "https": "xxx.xxx.xxx.xxx:8800",
    }
    with closing(requests.get(url, headers=_HTTP_HEADERS, proxies=HTTP_PROXY)) as response:
        response.raise_for_status()
        return response.content

Try this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.