iT邦幫忙

0

(急!!!!!!)爬蟲+line bot 問題

  • 分享至 

  • xImage

想請問要怎麼把執行出來的\n去除,且要如何放進line bot程式裡?
試了很久都用不出來
/images/emoticon/emoticon02.gif

import requests
from bs4 import BeautifulSoup

url1 = 'https://invoice.etax.nat.gov.tw/'
html1 = requests.get(url1)

moneys = [["期別","頭獎","特別獎","特獎","頭獎","增開六獎"]]

sp = BeautifulSoup(html1.text, 'lxml')

all1 = sp.find("div", class_="container-xl")
#print(all1)
date = sp.find("div", class_="carousel-item active").find('a')

tb = sp.find('span', class_='font-weight-bold etw-color-red')

t = sp.find_all('span', class_='font-weight-bold etw-color-red')[1]

head1 = sp.find("p", class_="etw-tbiggest mb-md-4")
head2 = sp.find_all("p", class_="etw-tbiggest mb-md-4")[1]
head3 = sp.find_all("p", class_="etw-tbiggest mb-md-4")[2]

add1 = sp.find_all("span", class_="font-weight-bold etw-color-red")

money=[date.text,
tb.text,
t.text,
head1.text,
head2.text,
head3.text,
add1[-1].text]
moneys.append(money)

for money in moneys:
print(money)

看到「急」,我就趕快去廁所了。
字串 \n 可以用replace 去掉
yun1231 iT邦新手 3 級 ‧ 2022-06-10 09:14:38 檢舉
多爬文
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
熊熊工程師
iT邦研究生 2 級 ‧ 2022-06-10 09:17:23

去除換行的部分參考:
https://www.w3schools.com/python/ref_string_replace.asp

放進去 linebot 程式內:

  1. 把整串程式碼直接塞到對應的 linebot 裡面
  2. 作為套件 import 進到 linebot 程式碼內 (網路上查很多)

我要發表回答

立即登入回答