Python 3.x 清除stackoverflow用户数据

Python 3.x 清除stackoverflow用户数据,python-3.x,web-scraping,Python 3.x,Web Scraping,当我们更改此代码的url时,输出保持不变。我遇到了类似的问题。适合我的解决方案是使用selenium。虽然我使用了无头浏览器,即phantomjs,但我认为它也适用于其他浏览器 import requests from bs4 import BeautifulSoup import csv response = requests.get('https://stackoverflow.com/users?page=3&tab=reputation&filter=week').te

当我们更改此代码的url时,输出保持不变。

我遇到了类似的问题。适合我的解决方案是使用
selenium
。虽然我使用了无头浏览器,即
phantomjs
,但我认为它也适用于其他浏览器

import requests
from bs4 import BeautifulSoup
import csv

response = requests.get('https://stackoverflow.com/users?page=3&tab=reputation&filter=week').text
soup = BeautifulSoup(response, 'lxml')
for items in soup.select('.user-details'):
    name = items.select("a")[0].text
    location = items.select(".user-location")[0].text
    reputation = items.select(".reputation-score")[0].text
    print(name,location,reputation)

    with open('stackdata.csv','a',newline='') as csv_file:
        writer = csv.writer(csv_file)
        writer.writerow([name,location,reputation])
更改
页码以获得所需结果


希望这会有帮助

这里的问题是什么?当我将url更改为输出保持不变时,我们建议使用SO API获取记录
driver = webdriver.PhantomJS('/home/practice/selenium/webdriver/phantomjs/bin/phantomjs')
users = []
page_num = 1
driver.get('https://stackoverflow.com/users?page={page_num}&tab=reputation&filter=week'.format(page_num=page_num))
content = driver.find_element_by_id('content')

for details in content.find_elements_by_class_name('user-details'):
    users.append(details.text)

print(users)