簡體   English   中英

urlopen 無法連接到網站

[英]urlopen doesn't work to connect to website

只是學習使用 python 編碼並嘗試一些基本的網絡抓取。 我已經在我的系統上安裝了 python 3.9 和 Anaconda,並安裝了一些 pip 庫。

這是我的代碼:

# Import requests (to download the page)
#pip install requests
import requests
import urllib3

# Import BeautifulSoup (to parse what we download)
#pip install BeautifulSoup4
from bs4 import BeautifulSoup as soup

http = urllib3.PoolManager()
r = http.request('GET', 'http://google.com')
page_html = r.read()
r = soup(page_html, "html.parser")

print(r)

但是,這是我得到的錯誤:

Blank (literally blank line)
[Finished in 0.9s]

任何幫助,將不勝感激! 我已經在谷歌上搜索了幾個小時無濟於事..

嘗試一下 :

from six.moves import urllib
from bs4 import BeautifulSoup as soup
r = urllib.request.urlopen('https://google.com')

s = soup(r, "html.parser")

print(s)

更新:

它在這里和 repl 網站上運行良好。 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM