-4
下面是我的網頁代碼。我期待返回正則表達式的結果,但由於某種原因,它只返回'[]'。爲什麼我的Python代碼不運行我的正則表達式?
任何幫助將非常感激。
感謝
import urllib.request
import re
url = ('https://www.myvue.com/whats-on')
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
def main():
html_page = urllib.request.urlopen(req).read()
content=html_page.decode(errors='ignore', encoding='utf-8')
headings = re.findall('<th scope="col" abbr="(.*?)">', content)
print(headings)
main()
嗯,因爲該模式沒有找到該網頁上的任何地方?你不應該使用正則表達式來解析多級/層次結構(比如HTML) - 使用爲此目的編寫的東西,比如['BeautifulSoup'](https://www.crummy.com/software/BeautifulSoup/bs4/DOC /)。 – zwer
[不要在HTML/XHTML上使用正則表達式](https://stackoverflow.com/a/1732454/1040092) – Wondercricket
@zwer我知道!但我被告知! – Jdsmith