另一种方法是使用当前的requests
模块。 你可以通过user-agent
这样的:
import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36'
}
page = requests.get("http://flow.gassco.no/", headers=headers)
soup = BeautifulSoup(page.text, 'html.parser')
编辑:为了使这个版本的工作简单,你可以做一个变通方法与浏览器会话。 您需要通过requests.get
a cookie
告知网站会话号码,其中条款和条件已被接受。
运行这段代码:
import requests
from bs4 import BeautifulSoup
url = "http://flow.gassco.no"
s = requests.Session()
r = s.get(url)
action = BeautifulSoup(r.content, 'html.parser').find('form').get('action') #this gives a "tail" of url whick indicates acceptance of Terms
s.get(url+action)
page = s.get(url).content
soup = BeautifulSoup(page, 'html.parser')
我想,你必须使用硒网络驱动程序绕过长期接受 – slesh
谢谢,我看看吧! –