예제 #1
0
def wikiAbstract(response):
    while 1:
        line = response.readline()
        if line.startswith("</table>"):
            break
    while 1:
        line = response.readline()
        if line.startswith("<p>"):
            print(CleanHTML.trim(line))
        elif line.startswith("<div"):
            break
예제 #2
0
def baikeAbstract(response):
    while 1:
        line = response.readline()
        if "<div class=\"lemma-summary\"" in line:
            break
    line = response.readline()
    while 1:
        if line.startswith("<div class=\"para\""):
            while not line == "</div>\n":
                print(CleanHTML.trim(line))
                line = response.readline()
            break
        else:
            line = response.readline()
        if "Search Results" in line and "Translations, word origin, and more definitions" in line:

            start = line.index("<span data-dobid=\"hdw\">")
            end = line.index("<div class=\"lr_dct_trns\"")
            return line[start:end]

        else:
            continue


if __name__ == '__main__':

    url = 'https://www.google.com/search?q='
    if len(sys.argv) == 1:
        word = 'play'
    else:
        word = sys.argv[1]

    query = word + ' definition'
    query = query.replace(' ', '+')
    query += '&ie=utf-8&oe=utf-8'
    url += query

    response = Bot('www.google.com',
                   'Bot0127').run(url)

    result = word_definition(response, word)
    if result is not None:
        print(CleanHTML.trim(result))