-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCrawler.py
More file actions
27 lines (22 loc) · 778 Bytes
/
Copy pathCrawler.py
File metadata and controls
27 lines (22 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import base64
import requests
from bs4 import BeautifulSoup
from urllib import parse
class PcStoreCrawler():
def fetchIt(self, inputText):
searchText = base64.b64encode(
str.encode(parse.quote(inputText))).decode()
url = "https://www.pcstore.com.tw/adm/psearch.htm?store_k_word=" + \
searchText + "&slt_k_option=1"
res = requests.get(url)
res.encoding = 'big5'
soup = BeautifulSoup(res.text, 'html.parser')
item = soup.select("div.pic2t_bg > a")
titleArray = []
for i in item:
titleArray.append(i.get_text())
return titleArray
print("This is example")
inputText = input("請輸入關鍵字: ")
crawlerOne = PcStoreCrawler()
print(crawlerOne.fetchIt(inputText))