2016-08-22 10 views
-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 And the error say that : http://imgur.com/403a6N8
I tried to fix it but it seems not to work, so any tips/answers how to fix it?PythonのBS4モジュール

EDIT: Sorry everyone for faulty title and tag, everything was fixed.

+0

あなたはあなたに何を伝えようとしましたか? 'soup = BeautifulSoup(plain_text、" html.parser "、markup_type = markup_type)'です。そして、判読不能なイメージではなく、エラーのテキスト版を投稿してください。 –

+0

これは 'requests'モジュールとは関係ありません。 – DeepSpace

+0

@ Jean-FrançoisFabre悪い写真のために申し訳ありませんが、あなたは正しい誤りを読みました。しかし、問題は、私は私のコードにその行を貼り付け、エラーが表示されます:SyntaxError:識別子の無効な文字です。いくつかの奇妙な理由のために私はそれが間違っているものを見つけることができません。そして、ここに以前のエラーがあります:http://pastebin.com/HNL1ENG0 – Auginis

答えて

1

あなたがラインでBeatifulSoupオブジェクトを作成しようとしている、代わりにこれを行う:

soup = BeautifulSoup(plain_text) 

この:

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

注:あなたの問題はBS4モジュールを指し、 、要求ではない。

+0

すみませんが、タイトルとタグが間違っていて申し訳ありません。返事をしてくれてありがとうございます。しかし、この行を書いています。SyntaxError:識別子の文字が無効です。 imgur.com/a/8NBDi – Auginis

+0

markup_typeを指定していない場合、soup = BeautifulSoup(plain_text、 'html.parser')ではなくsoup = BeautifulSoup(plain_text、 'html.parser'、markup_type = markup_ty pe )。私の反応が役に立ったら、それを有用とマークしてください。 – dannyxn

+0

あなたのニーズに合った答えを変更しました。私は見て参照してください:https://www.crummy.com/software/BeautifulSoup/bs4/doc/。 – dannyxn

0

これは、要求モジュールとは全く無関係です。 Jean-Francois氏は、あなたに何を伝え、それに沿って動いているのかを述べます。

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

+0

すみません、タイトルとタグが間違っていて申し訳ありません(私の悪い)答えがありがたいですが、私は次の行を書いています:SyntaxError :識別子の文字が無効です。 http://imgur.com/a/8NBDi – Auginis

関連する問題