現在我的輸出到一個文件是這樣的:替換字符串的所有實例的字符串的Python
<b>Nov 22–24</b> <b>Nov 29–Dec 1</b> <b>Dec 6–8</b> <b>Dec 13–15</b> <b>Dec 20–22</b> <b>Dec 27–29</b> <b>Jan 3–5</b> <b>Jan 10–12</b> <b>Jan 17–19</b> <b><i>Jan 17–20</i></b> <b>Jan 24–26</b> <b>Jan 31–Feb 2</b> <b>Feb 7–9</b> <b>Feb 14–16</b> <b><i>Feb 14–17</i></b> <b>Feb 21–23</b> <b>Feb 28–Mar 2</b> <b>Mar 7–9</b> <b>Mar 14–16</b> <b>Mar 21–23</b> <b>Mar 28–30</b>
我想刪除所有「A」和CSS標籤(< B>,</B>) 。我嘗試過使用卸下襬臂和.replace功能,但我得到一個錯誤:
SyntaxError: Non-ASCII character '\xc2' in file -- FILE NAME-- on line 70, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
上面的輸出是一個列表,這是我從一個webcrawling功能得到:
def getWeekend(item_url):
dates = []
href = item_url[:37]+"page=weekend&" + item_url[37:]
response = requests.get(href)
soup = BeautifulSoup(response.content, "lxml") # or BeautifulSoup(response.content, "html5lib")
date= soup.select('table.chart-wide > tr > td > nobr > font > a > b')
return date
我把它寫入一個像這樣的文件:
for item in listOfDate:
wr.writerow(item)
如何刪除所有標籤,以便只剩下日期?
什麼是頁面編碼? –