Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit573368b

Browse files
authored
Add files via upload
1 parent3dc9856 commit573368b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎scraper.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
importrequests
2+
frombs4importBeautifulSoup
3+
4+
proxy= {'http':'http://SPusername:SPpassword@gate.smartproxy.com:7000'}
5+
url='http://books.toscrape.com/catalogue/page-1.html'
6+
7+
r=requests.get(url,proxies=proxy)
8+
html=BeautifulSoup(r.content,'html.parser')
9+
10+
all_books=html.find_all('article',class_='product_pod')
11+
12+
forbookinall_books:
13+
title=book.h3.a['title']
14+
price=book.find('p',class_='price_color').text
15+
availability=book.find('p',class_='instock availability').text.strip()
16+
link_to_book=book.h3.a['href']
17+
18+
link="http://books.toscrape.com/catalogue/{0}".format(link_to_book)
19+
20+
r2=requests.get(link)
21+
html2=BeautifulSoup(r2.content,'html.parser')
22+
23+
description=html2.find('p',class_='').text
24+
25+
print(title)
26+
print(price)
27+
print(availability)
28+
print("{0}...".format(description[:150]))
29+
print(link)
30+
print()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp