仅使用multiprocessing.dummy导入池请求异常

时间:2017-02-10 11:59:26

标签: python-3.x parsing multiprocessing python-requests

import requests
from requests import Session
from bs4 import BeautifulSoup
import re
from multiprocessing.dummy import Pool as ThreadPool

def get_total_pages():
    tut = []
    base_url = 'Your group '
    for url in [base_url % i for i in range(1, 27)]:
        tut.append(url)
    print(tut)
    #get_data_from_page(tut)
    pool = ThreadPool(8)
    results = pool.map(get_data_from_page, tut)

def get_data_from_page(tut):
    f = open("emails.txt", 'a')
    email = []
    for a in tut:
        link = s.get(a).text
        soup = BeautifulSoup(link, 'lxml')
        links = soup.find('div', class_="mens").find_all('span', class_="inviz")
        for e in links:
            emails = e.text
            f.write(emails + ', ')
            email.append(emails)
    print(email)

def main():
    get_total_pages()
if __name__ == '__main__':
    main()

这会导致错误,说它只适用于多处理,并且:

raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'h': No schema supplied. Perhaps you meant http://h?

1 个答案:

答案 0 :(得分:1)

问题在于此

 for a in tut:
  link = s.get(a).text

并且需要

link = s.get(a).text
#without for