示例#1
0
def generar_consulta_bing(q):
    reload(sys)
    sys.setdefaultencoding('utf8')

    engine_bing = Bing(license="TNMHm68dvf440pSPdnU+2LqxeQi7J2xszPZLBiPYsmI",
                       throttle=0.5,
                       language=None)
    bing = []
    for consulta in q:
        request = asynchronous(engine_bing.search,
                               consulta,
                               start=1,
                               count=20,
                               type=SEARCH,
                               timeout=10)
        while not request.done:
            time.sleep(0.01)
        #
        # # An error occured in engine.search(), raise it.
        if request.error:
            raise request.error
        #
        # # Retrieve the list of search results.
        for result in request.value:
            bing.append(result.url)

    return bing
示例#2
0
def generar_consulta_bing(q):    
    reload(sys)
    sys.setdefaultencoding('utf8')

    engine_bing = Bing(license="TNMHm68dvf440pSPdnU+2LqxeQi7J2xszPZLBiPYsmI", language="en")
    bing = []
    for consulta in q:
        request = asynchronous(engine_bing.search, consulta, start=1, count=10, type=SEARCH, timeout=10)

        while not request.done:
            time.sleep(0.01)

        # An error occured in engine.search(), raise it.
        if request.error:
            raise request.error

        # Retrieve the list of search results.
        for result in request.value:
            bing.append(result.url)

    return bing
示例#3
0
file.write(page_url.download())
file.close()

# ### Finding URLs within Text

from pattern.web import find_urls

print(find_urls('To search anything, go to www.google.com', unique=True))

# ### Making Asynchronous Requests for Webpages

from pattern.web import asynchronous, time, Google

asyn_req = asynchronous(Google().search, 'artificial intelligence', timeout=4)
while not asyn_req.done:
    time.sleep(0.1)
    print('searching...')

print(asyn_req.value)

print(find_urls(asyn_req.value, unique=True))

# ### Getting Search Engine Results with APIs

# #### Google

from pattern.web import Google

google = Google(license=None)
for search_result in google.search('artificial intelligence'):
    print(search_result.url)
from pattern.web import time,Twitter

engine = Twitter(license=None, throttle=0.5, language=None)
s = engine.stream('#DMCLatam2013')
for tweet in range(10):
    time.sleep(1)
    s.update(bytes=1024)
    print s[-1].text if s else ''