windows 与 linux python 爬虫获取源代码不同

版本

系统:windows 10
编辑器:pycharm
python: 3.9.1
chrome: 89.0.4389.114
ChromeDriver 89.0.4389.23
bs4: 0.0.1
requestium: 0.1.9
selenium: 3.141.0

代码

from bs4 import BeautifulSoup
from requestium import Session

def main():
    url = "https://www.zhibo8.cc/"
    s = Session(webdriver_path="D:\\venv\\Scripts\\chromedriver.exe",
                browser='chrome',
                default_timeout=15,
                webdriver_options={'arguments': ['headless']})
    s.driver.get(url)
    # 点击事件
    s.driver.find_element_by_css_selector('.c_nav a:nth-child(2)').click()
    # 获取源码
    html = s.driver.page_source
    content = BeautifulSoup(html, 'html.parser')
    lis = content.find_all(style="display: list-item;")
    for line in lis:
        print(line)
        exit()

if __name__ == '__main__':
    main()

正常的结果内容

<li data-time="2021-04-08 15:00" id="saishi625115" label="中国女足,韩国女足,奥女足,足球" style="display: list-item;">15:00 <b>奥女足附加赛首回合 韩国女足 <img src="//duihui.duoduocdn.c
om/zuqiu/hanguonvzu1.png"/> <span style="font-weight: bold;">1 - 1</span> <img src="//duihui.duoduocdn.com/zuqiu/zhongguo.png"/> 中国女足</b> <a href="/zhibo/zuqiu/2021/match625115v.ht
m" target="_blank">CCTV5 足球直播</a> <a href="https://www.zhibo8.cc/zhibo/zuqiu/2021/match625115v.htm" target="_blank">文字</a> <a href="//www.zhibo8.cc/shouji.htm" target="_blank">手
机看直播</a> <a href="http://www.188bifen.com/" target="_blank">比分</a> <a href="https://www.zhibo8.cc/zhibo/zuqiu/2021/match625115v.htm?redirect=animate" target="_blank">动画</a> <a
href="http://nbaftx.wanjiashe.com/game.php?sid=56" target="_blank">NBA范特西56服</a> </li>

=============================

问题描述:

代码放到centos后,标签li中没有iddata-time属性

版本

系统:centos 7.6
编辑器:vim
python: 3.6.8
chrome: 89.0.4389.114
ChromeDriver 89.0.4389.23
bs4: 0.0.1
requestium: 0.1.9
selenium: 3.141.0

代码

from bs4 import BeautifulSoup
from requestium import Session

def main():
    url = "https://www.zhibo8.cc/"
    s = Session(webdriver_path="/usr/local/src/chromedriver",
                browser='chrome',
                default_timeout=15,
                webdriver_options={'arguments': ['headless','no-sandbox']})
    s.driver.get(url)
    s.driver.find_element_by_css_selector('.c_nav a:nth-child(2)').click()
    html = s.driver.page_source
    content = BeautifulSoup(html, 'html.parser')
    lis = content.find_all(style="display: list-item;")
    for line in lis:
        print(line)
        exit()

if __name__ == '__main__':
    main()

有问题的结果

<li label="中国女足,韩国女足,奥女足,足球" style="display: list-item;">15:00 <b>奥女足附加赛首回合 韩国女足 <img src="http://duihui.duoduocdn.com/zuqiu/hanguonvzu1.png"/> - <img src="http://duihui.duoduocdn.com/zuqiu/zhongguo.png"/> 中国女足</b> <a href="/zhibo/zuqiu/2021/match625115v.htm" target="_blank">CCTV5 足球直播</a> <a href="https://www.zhibo8.cc/zhibo/zuqiu/2021/match625115v.htm" target="_blank">文字</a> <a href="http://www.188bifen.com/" target="_blank">比分</a> <a href="http://nbaftx.wanjiashe.com/game.php?sid=56" target="_blank">NBA范特西56服</a> </li>
讨论数量: 3

最早用 phantomjs, 后来换成selenium + chrome | firefox, 结果在windows上正常,在centos会有问题

3年前 评论
SilenceHL 3年前

你可以查看一下centos下直播⑧页面对应位置有没有iddata-time属性

3年前 评论

@SilenceHL 已看过,确实没有。后来我伪装user-agent为Windows NT 一样拿不到

3年前 评论
SilenceHL 3年前
charliecen (作者) (楼主) 3年前
SilenceHL 3年前
charliecen (作者) (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!