-2
import requests
from bs4 import BeautifulSoup

'''
It's a web crawler working in ebay, collecting every single item data
'''

def ebay_spider(max_pages):
    page = 1
    while page <= max_pages:
        url = 'http://www.ebay.co.uk/sch/Apple-Laptops/111422/i.html?_pgn=' \
              + str(page)
        source_code = requests.get(url)

        plain_text = source_code.text
        soup = BeautifulSoup(plain_text)
        for link in soup.findAll('a', {'class': 'vip'}):
            href = 'http://www.ebay.co.uk' + link.get('href')
            title = link.string
    get_single_item_data(href)
    page += 1


def get_single_item_data(item_url):
    source_code = requests.get(item_url)
    plain_text = source_code.text
    soup = BeautifulSoup(plain_text)
    for item_name in soup.findAll('h1', {'id': "itemTitle"}):
        print(item_name.string)

ebay_spider(3)

Blockquote 并且错误说:http: //imgur.com/403a6N8
我试图修复它,但它似乎不起作用,所以任何提示/答案如何修复它?

编辑:对不起大家错误的标题和标签,一切都已修复。

4

2 回答 2

1

当您尝试在线制作 BeatifulSoup 对象时,请改为执行以下操作:

soup = BeautifulSoup(plain_text)

这:

soup = BeautifulSoup(plain_text, 'html.parser')

注意:您的问题是指 bs4 模块,而不是请求。

于 2016-08-22T18:57:50.753 回答
0

这与请求模块完全无关。正如让-弗朗索瓦所说,做它告诉你的事情并继续前进。

soup = BeautifulSoup(plain_text,"html.parser",markup_type=markup_ty‌​pe)

于 2016-08-22T18:56:35.700 回答