python3抓取数据_用python3从网页上抓取数据,需要登录firs

我检查了this question,但它只有一个答案,而且有点超出我的理解范围(刚从Python开始)。我用的是python3。在

我试图从this page中获取数据,但是如果你有一个BP帐户,那么这个页面就大不相同了/更有用。我需要我的程序登录我之前,我有美化小组为我获取数据。在

到目前为止from bs4 import BeautifulSoup

import urllib.request

import requests

username = 'myUsername'

password = 'myPassword'

from requests import session

payload = {'action': 'Log in',

'Username: ': username,

'Password: ': password}

# the next 3 lines are pretty much copied from a different StackOverflow

# question. I don't really understand what they're doing, and obviously these

# are where the problem is.

with session() as c:

c.post('https://www.baseballprospectus.com/manageprofile.php', data=payload)

response = c.get('http://www.baseballprospectus.com/sortable/index.php?cid=1820315')

soup = BeautifulSoup(response.content, "lxml")

for row in soup.find_all('tr')[7:]:

cells = row.find_all('td')

name = cells[1].text

print(name)

这个脚本确实有效,它只是在登录之前从站点提取数据,所以它不是我想要的数据。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值