以下代码摘录网页信息
from BeautifulSoup import BeautifulSoup
import requests
import urllib2
url = 'http://www.surfline.com/surf-report/rincon-southern-california_4197/'
source_code = requests.get(url)
plain_text = source_code.text
print plain_text
site = urllib2.urlopen(url).read()
print site这两个图书馆的结果包括:
<div id="current-surf-range" style="font-size:21px;font-weight:bold;padding-top:7px; padding-bottom: 7px;"></div>不幸的是,这与实际的网页不同:
<div id="current-surf-range" style="font-size:21px;font-weight:bold;padding-top:7px; padding-bottom: 7px;">4-5ft</div>4-5英尺长的不存在,因此不能被BeautifulSoup提取.
发布于 2016-01-19 20:47:21
selenium中安装完整的文档指令。pip3安装硒
从selenium导入webdriver = '4197/‘web = webdriver.Firefox() # web = webdriver.Remote('http://localhost:9515',http://localhost:9515' source_code = web.get( url ) #)有时加载页面需要时间--这就是为什么:从时间导入睡眠;睡眠(2) plain_text = source_code.page_source
https://stackoverflow.com/questions/34884534
复制相似问题