python爬蟲範例(mobile01 爬蟲電腦版為例)
import requests
from bs4 import BeautifulSoup
page = int(input("請輸入要擷取的頁數"))
for i in range(1,page+1):
res = requests.get("https://www.mobile01.com/forumtopic.php?c=17&p="+ str(i))
soup = BeautifulSoup(res.text,"html.parser")
for title in soup.select(".topic_gen"):
print ("==============")
url = str(title.get('href'))
print ("[標題]:"+title.text,"\n"+"https://www.mobile01.com/"+url)
from bs4 import BeautifulSoup
page = int(input("請輸入要擷取的頁數"))
for i in range(1,page+1):
res = requests.get("https://www.mobile01.com/forumtopic.php?c=17&p="+ str(i))
soup = BeautifulSoup(res.text,"html.parser")
for title in soup.select(".topic_gen"):
print ("==============")
url = str(title.get('href'))
print ("[標題]:"+title.text,"\n"+"https://www.mobile01.com/"+url)
留言
張貼留言