在某些页面中,当我使用 beautifulsoup 时,什么都不返回...只是空白页面。
from bs4 import BeautifulSoup
import urllib.request
Site = "http://gall.dcinside.com/board/lists/?id=parkbogum&page=2"
URL = Site
html = urllib.request.urlopen(URL).read()
soup = BeautifulSoup(html, "html.parser")
print(soup)
我可以在除此站点以外的任何其他站点上使用 beautifulsoup。我不知道怎么...
请您参考如下方法:
此 URL 将要求在请求时传递某些 header 。 在请求 URL 时传递此 header 参数,您将获得 HTML。
HTML = requests.get(URL , headers = headers).content
同时
headers = {
"method":"GET",
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36",
"Host":"gall.dcinside.com",
"Pragma":"no-cache",
"Upgrade-Insecure-Requests":"1",
"Accept":"text/html,application/xhtml+xml,
application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
}
